方法和结果的简单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与Groovy正则表达式匹配混淆   java控制台未定义为JSNI   主目录中的java指针异常   java如何获取hashmap中的arrayList的大小   ApachePOI用于文本,Java代码中的word doc(.docx)中没有进行追加   Ruby对象到Java对象   JavaSpringJPA哈希集只返回一个值   Java在执行由配置了精确类路径参数的mavenjarpluin生成的可执行jar时无法找到依赖项   java我试图在画布上写一个文本,但什么也没发生   java HTTP 404源服务器找不到目标资源的当前表示形式,或者不愿意透露存在该表示形式。不起作用   java提取小数点后的最后一个数字   oop Java:无法访问对象的元素   PHP URL中RecyclerView中的java句柄空异常   不调用OnCreateViewHolder的java Update RecyclerView适配器项