具有定时缓存和缓存感知速率限制选项的缓存包

memorize的Python项目详细描述


https://img.shields.io/badge/Made%20with-Python-1f425f.svghttps://img.shields.io/pypi/v/memorize.svghttps://img.shields.io/pypi/l/memorize.svghttps://img.shields.io/pypi/pyversions/memorize.svg

安装

要安装memory,只需使用pip:

$ pip install memorize

或直接从源安装以包含最新更改:

$ pip install git+https://github.com/saporitigianni/memorize.git

或克隆然后安装:

$ git clone https://github.com/saporitigianni/memorize.git
$ cd memorize
$ python3 setup.py install

用法

此类扩展functools.lru_缓存功能,以添加定时缓存和缓存感知速率限制 (例如,如果从缓存返回呼叫结果,则该特定呼叫不会影响速率限制)

约束:
  • 由于字典用于缓存结果,函数的位置参数和关键字参数必须是散列的(而不是列表、dict、set或任何其他未定义hash()的对象)
  • 即使是空的,也要使用括号:@memory()而不是@memory
  • 在限制速率时,必须同时提供调用句点参数,否则将引发错误
默认设置:
  • 超时=无(可以是int或float)
  • maxsize=none(可以是int)
  • 键入=false(可以为true)
  • 调用=无(可以是int)
  • 句点=无(可以是int或float)
  • aware=false(可以是true)
frommemorizeimportmemorize# If you want to use all default settings@memorize()deffib(n):ifn<2:returnnelse:returnfib(n-2)+fib(n-1)# With memorization fib(20) will be run 21 times instead of 21891 times# without memorizationfib(20)# If you want to cache a maximum of 128 calls, cached by different types,# each for 10 seconds use:@memorize(timeout=10,maxsize=128,typed=True)# If you want to implement caching aware rate limiting then use the following:# This will limit to no more than 10 calls for every 5 second period and if a# result is returned from the cache it does not count towards the 10 calls.@memorize(calls=10,period=5,aware=True)

贡献

在进行希望在代码中采用的更改之前,请阅读CONTRIBUTING文档。

行为准则

memorize项目的代码库中进行交互的每个人,问题 跟踪程序、聊天室和邮件列表应遵循 PyPA Code of Conduct.:八达通:



以太网0xAD1F09626B8E701D5F0F4A237193DF73D3C445
BTC 199zsvqcusefv8yjdyqhuqzmlcyh75dqnv
LTC润滑油7vxc43ttpsqum1jazfmshktau1rs9

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

推荐PyPI第三方库


热门话题
java将Map<String,String>传递给需要Map<String,Object>   java在循环中使用字符串而不是StringBuilder是否会造成内存损失?   jnlp如何更新java控制台JRE?   java更改、修改和重新打包CXFAPI源文件   JavaFXJava应用程序在Fedora上运行一段时间后关闭   使用来自不同类的方法的java   java如何通过ant脚本在linux中使用subst?   java在使用camunda modeler进行base64编码/解码时出错   获取java。netbeans、weblogic和fastswap设置为true时的lang.NoSuchMethodError   java如何提高FinalizerThread在GC中收集对象的优先级   java检测具有相同根的单词   netbeans crud应用程序中的java错误