☯️

python

尝试自己写一个Python缓存装饰器

python
本文记录尝试编写一个简单的缓存装饰器,以学习为目的,实际生产环境建议大家用标准库。 from hashlib import md5 from pickle import dump, load # 用pickle进行数据的读取、写入 def _dkL(f): with open(f,'rb') as file: return load(file) def _dkD(o,f): with open(f, 'wb') as file: return dump(o,file) def cache(ex_time=10, start=0, have_args=True, have_kw=True, cache_path="/tmp/pyCache"): # 判断缓存目录是否存在 if not path. Read more...
1 of 1