python函数的本地磁盘缓存装饰器。

cache-to-disk的Python项目详细描述


缓存到磁盘

具有自动失效的python函数的本地磁盘缓存装饰器。

这是为了缓存运行时间较长的函数,并且返回值占用的内存太多,无法用redis缓存在内存中。函数的结果将被pickle并保存到文件中,然后取消pickle并在下次调用函数时返回。缓存是特定于参数的,因此如果使用不同的参数调用该函数,则将再次运行该函数。缓存修饰符接受一个整数,表示要为其缓存函数的天数。过了这么多天,下次导入此模块时,将删除该函数的文件。

安装

pip install cache_to_disk

功能:

缓存到磁盘(n天缓存)delete_disk_caches_for_function(function_name)

示例:

缓存到磁盘

"""This example caches the function "my_function" for 3 days."""fromcache_to_diskimportcache_to_disk@cache_to_disk(3)defmy_function():to_return=[]foriinrange(10000):forjinrange(i):to_return.append(i*j**.23)returnto_return

delete_disk_caches_for_函数

"""This example invalidates all of the caches for the function "my_function". The function will be invalidated automatically, but this should be used when the function definition has been changed and you want it to re-run."""fromcache_to_diskimportdelete_disk_caches_for_functiondelete_disk_caches_for_function('my_function')

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java无法启动应用程序:JNLP错误   java根据用户输入在PreparedStatement中使用setTime()或setNull()   java EJB与同步   java以object为键通过hashmap进行搜索   java中的模10^9+7   针对包含其他对象的对象的java OOP最佳实践   如何将字符串作为HTML代码从Java文件读取到JSP页面?   java我的POM怎么了?“解析表达式..检测到递归表达式循环”   用于Hbase的Mapreduce的java NoSuchMethodError   JAVAlang.SecurityException:权限拒绝:启动意图{act=安卓.Intent.action.MAIN cat=[安卓.Intent.category.LAUNCHER]   数组初始化谜语Java   通过arraylist搜索时的java句柄关联