datetime
inspect
inspect signatureParameter
(fn):
local_cache={}
(*agrs**kwargs):
clear_list= []
k(_stamp) local_cache.items(): star = datetime.datetime.now().timestamp()
star - stamp >:
clear_list.append(k)
k clear_list: local_cache.pop(k)
paramers_dict = {} sig = inspect.signature(fn)
parameters = sig._parameters params_name = [key key parameters.keys()]
ivalues (agrs):
k = params_name[i]
paramers_dict[k] = values
kv kwargs.items():
paramers_dict[k] = v
kv parameters.items():
k parameters.keys():
parameters[k]= v.default
new_paramers_dict = ((parameters)) new_paramers_dict local_cache.keys(): local_cache[new_paramers_dict] = (fn(*agrs**kwargs)datetime.datetime.now().timestamp()) local_cache[new_paramers_dict] wrapper
time
(x=y=):time.sleep()
x+y
(add())
()
(add())
当前名称:缓存装饰器的练习
浏览地址:
http://cdweb.net/article/pdsohi.html