【发布时间】:2015-08-24 05:00:21
【问题描述】:
如何让@functools.lru_cache 装饰器忽略一些关于缓存键的函数参数?
例如,我有一个如下所示的函数:
def find_object(db_handle, query):
# (omitted code)
return result
如果我像这样应用lru_cache 装饰器,db_handle 将包含在缓存键中。结果,如果我尝试使用相同的query,但不同的db_handle 调用该函数,它将再次执行,我想避免这种情况。我希望 lru_cache 仅考虑 query 参数。
【问题讨论】:
标签: python caching python-decorators lru functools