支持节流、过期和压缩的django web缓存应用程序。

django-webcache的Python项目详细描述


Django网络缓存

支持限制、过期和 压缩。

这使用django 1.6中的代码来限制事务。如果你 使用的是django 1.5或更低版本,你可能会幸运地参加比赛 条件(如果有并发请求)。在这种情况下 跳过那个查找的限制。

安装

pipinstalldjango-webcache

使用量

除了url之外,所有变量都有默认值,可以在 settings.py文件

fromurlopenimportcachefromurlopenimportthrottlefromurlopenimportcache_and_throttle

缓存

cache(url[,data=postdata][,location="path"][,expires=n|,expires=(n,m)][,overwrite=False][,compression=False])
variabletypedescription
urlstringThe url to retrieve / cache
datastringurlencoded POST data string
locationstringThe directory to save the cached pages to
expiresinteger or 2 item tuple of integersNumber of seconds until the cache expires, or a range from which a random number of seconds will be chosen for the expiration
overwritebooleanRetrieve url and cache even if cache already exists
compressionstringCompress the cache

节气门

throttle(url[,data=postdata][,delay=n|,delay=(n,m)])
variabletypedescription
urlstringThe url to retrieve / cache
datastringurlencoded POST data string
delayinteger or 2 item tuple of integersNumber of seconds to throttle, or a range from which a random number will be chosen to throttle

缓存和节流

cache_and_throttle(url[,data=postdata][,location="path"][,expires=n|,expires=(n,m)][,overwrite=False][,compression=False][,delay=n|,delay=(n,m)])
variabletypedescription
urlstringThe url to retrieve / cache
datastringurlencoded POST data string
locationstringThe directory to save the cached pages to
expiresinteger or 2 item tuple of integersNumber of seconds until the cache expires, or a range from which a random number of seconds will be chosen for the expiration
overwritebooleanRetrieve url and cache even if cache already exists
compressionstringCompress the cache
delayinteger or 2 item tuple of integersNumber of seconds to throttle, or a range from which a random number of seconds will be chosen to throttle

示例

importwebcache.urlopenimporturllibpyurl="http://www.python.org/""""just caching"""response=urlopen.cache(pyurl)"""caching with post data"""postdata=urllib.urlencode({"name":"value"})response=urlopen.cache(pyurl,data=postdata)"""cache and override default cache file directory"""response=urlopen.cache(pyurl,location=self.path)"""cache and override default expiration time in seconds"""response=urlopen.cache(pyurl,expires=10)"""cache and override default overwrite setting
   will overwrite old cache even if not expired"""response=urlopen.cache(pyurl,overwrite=True)"""cache and override default compression with gzip compression"""response=urlopen.cache(pyurl,compression='gzip')"""throttle will wait 10 seconds since the previous web page retrieval of something
   from the same site. For example http://www.python.org/about will throttle if
   another lookup of http://www.python.org exists in the last 10 seconds"""response=urlopen.throttle(pyurl,delay=10)"""throttle using random range"""response=urlopen.throttle(pyurl,delay=(60,120))"""combination of cache and throttle"""response=urlopen.cache_and_throttle(pyurl,location=self.path,delay=10)

特别感谢

许可证

麻省理工学院许可证(MIT)

版权所有(c)2013 Drew Thomson

特此免费向任何获得 本软件和相关文档文件的副本 “软件”),无限制地处理软件,包括 但不限于使用、复制、修改、合并、发布, 分发、再授权和/或出售软件副本,以及 允许向其提供软件的人员这样做,但须遵守 以下条件:

上述版权公告及本许可公告须包括在内 在软件的所有副本或大部分中。

软件按“原样”提供,不作任何形式的保证 或默示的,包括但不限于 适销性、适合特定目的和不侵权。 在任何情况下,作者或版权持有人均不对任何 索赔、损害赔偿或其他责任,无论是在合同诉讼中, 侵权行为或其他,由 软件或软件中的使用或其他交易。

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

推荐PyPI第三方库


热门话题
java将Scanner对象作为构造函数参数传递给UserInterface类   spring未能启动bean“subtocolWebSocketHandler”;嵌套的例外是java。lang.IllegalArgumentException:没有处理程序   Java EE应用程序中后台服务的多线程Java线程(设置守护进程和优先级)?   java Pull to refresh返回列表的第一个位置   无法将comparator类转换为java。可比的   java将json从servlet传递到dojo   JavaHibernate:将子类实例转换为超类实例   java警告调用servlet类时非法反射访问   java静态变量值   java@Entity和@embeddeble之间有什么区别   java将作业配置导入公共作业配置类(注释配置)   sql公共表表达式(以values语句开头)在java中给出错误   java在ImageJ中使用ImageProcessor   java PostgreSQL executeBatch()会随着时间的推移而变慢   java在安卓中以表格形式排列sqllite表数据?   java中SVG的swing定制呈现   java删除与另一个实体映射的实体   java何时/如何添加ListView适配器,使用back按钮恢复它?(片段)   java为什么IBinder和Binder之间的类型转换不是非法的?   java在方法参数列表中使用ArrayList或List