方法和结果的简单ttl缓存。

method-cache的Python项目详细描述


python方法缓存

Build StatusPyPI versionDocumentation Status

它的功能

方法缓存可用于以灵活的方式缓存方法的结果。 这个libary没有依赖项!

当前只有TTL缓存可用

缓存存储可以按类别分段。 具有@cache装饰符的方法保存在这些类别中。

示例

frommethodcacheimportcache,Storeimporttime# TTL in Seconds (Default TTl is 60)st=Store(ttl=60*300)# Define Store for this Cache, and overwrite Store TTL. And categorize this cache object to demo@cache(store=st,ttl=5,category="demo")defdoothings(a,b,c):# Do here what ever you want.# eg. MySQL querys or other slow operationstime.sleep(2)returna+b+c# Slow Executiondoothings(1,2,3)# Slow Executiondoothings(4,5,6)# Fast Execution because the Cache was useddoothings(1,2,3)time.sleep(2)# Slow Execution because the Cache TTL is Expireddoothings(1,2,3)

文档

Read the Docs

或者 显示example.py

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

推荐PyPI第三方库


热门话题
java Android将字符串拆分为数组   java如何读取底层HttpServerExchange对象中的响应数据?   在jenkins上安装gitplugin时出现java错误   java DecimalFormat格式decimal,用于保留可变数量的尾随零   java Jaxws、spring和SpringBeanAutowiringSupport   Gson中抽象类的java反序列化   监视Windows服务器中的UDP数据包丢失,Java   java从侦听器调用所有者类   java Scala和Robocode类循环错误   java映像未上载到数据库   java如何将XML文件直接写入zip存档?   java为什么需要EventSourcingHandler(在聚合对象中)?   接受特定对象或其子类型的java通用方法   java Spring安全过滤器映射在特定Url模式上禁用