支持节流、过期和压缩的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])
variable | type | description |
---|---|---|
url | string | The url to retrieve / cache |
data | string | urlencoded POST data string |
location | string | The directory to save the cached pages to |
expires | integer or 2 item tuple of integers | Number of seconds until the cache expires, or a range from which a random number of seconds will be chosen for the expiration |
overwrite | boolean | Retrieve url and cache even if cache already exists |
compression | string | Compress the cache |
节气门
throttle(url[,data=postdata][,delay=n|,delay=(n,m)])
variable | type | description |
---|---|---|
url | string | The url to retrieve / cache |
data | string | urlencoded POST data string |
delay | integer or 2 item tuple of integers | Number 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)])
variable | type | description |
---|---|---|
url | string | The url to retrieve / cache |
data | string | urlencoded POST data string |
location | string | The directory to save the cached pages to |
expires | integer or 2 item tuple of integers | Number of seconds until the cache expires, or a range from which a random number of seconds will be chosen for the expiration |
overwrite | boolean | Retrieve url and cache even if cache already exists |
compression | string | Compress the cache |
delay | integer or 2 item tuple of integers | Number 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)
由
- 德鲁汤姆森-drooby@gmail.com
特别感谢
许可证
麻省理工学院许可证(MIT)
版权所有(c)2013 Drew Thomson
特此免费向任何获得 本软件和相关文档文件的副本 “软件”),无限制地处理软件,包括 但不限于使用、复制、修改、合并、发布, 分发、再授权和/或出售软件副本,以及 允许向其提供软件的人员这样做,但须遵守 以下条件:
上述版权公告及本许可公告须包括在内 在软件的所有副本或大部分中。
软件按“原样”提供,不作任何形式的保证 或默示的,包括但不限于 适销性、适合特定目的和不侵权。 在任何情况下,作者或版权持有人均不对任何 索赔、损害赔偿或其他责任,无论是在合同诉讼中, 侵权行为或其他,由 软件或软件中的使用或其他交易。