从本地范围将忽略参数传递给记忆缓存(diskcache python)

问题描述 投票:0回答:1

如何从本地范围将忽略参数传递到磁盘缓存中的记忆缓存。
有没有比围绕缓存函数编写包装函数更好的方法?
错误: 未解决的忽略参考= {threshold_days,folder_path}

import diskcache as dc
from datetime import datetime

cache = dc.Cache()
#LocalScope issue - Undefined Reference ignore={threshold_days, folder_path}
@dc.Cache().memoize(tag='runoncetoday', ignore={threshold_days, folder_path})
def delete_olddata_func(day_today):
#     run file deleteion function only once at the start of the day and skip it when called again on the same day .
    pass

if __name__ == "__main__" :
    day_today = datetime.now().date()
    threshold_days = 25
    folder_path = "/myDir"

    delete_olddata_func(day_today=day_today, threshold_days=threshold_days, folder_path = folder_path )
python-3.x diskcache
1个回答
0
投票
from diskcache import Cache
cache = Cache('/path/to/cache')
@cache.memoize(ttl=60, ignore=['threshold_days', 'folder_path'])
def my_function(threshold_days, folder_path, other_arg):
#function implementation
pass
© www.soinside.com 2019 - 2024. All rights reserved.