diskcache
DiskCache: Disk Backed Cache
DiskCache is an Apache2 licensed disk and file backed cache library, written in pure-Python, and compatible with Django.
The cloud-based computing of 2018 puts a premium on memory. Gigabytes of empty space is left on disks as processes vie for memory. Among these processes is Memcached (and sometimes Redis) which is used as a cache. Wouldn’t it be nice to leverage empty disk space for caching?
Django is Python’s most popular web framework and ships with several caching backends. Unfortunately the file-based cache in Django is essentially broken. The culling method is random and large caches repeatedly scan a cache directory which slows linearly with growth. Can you really allow it to take sixty milliseconds to store a key in a cache with a thousand items?
In Python, we can do better. And we can do it in pure-Python!
In [1]: import pylibmc
In [2]: client = pylibmc.Client(['127.0.0.1'], binary=True)
In [3]: client[b'key'] = b'value'
In [4]: %timeit client[b'key'] 10000 loops, best of 3: 25.4 µs per loop In [5]: import diskcache as dc
In [6]: cache = dc.Cache('tmp')
In [7]: cache[b'key'] = b'value'
In [8]: %timeit cache[b'key'] 100000 loops, best of 3: 11.8 µs per loop
Note: Micro-benchmarks have their place but are not a substitute for real measurements. DiskCache offers cache benchmarks to defend its performance claims. Micro-optimizations are avoided but your mileage may vary.
DiskCache efficiently makes gigabytes of storage space available for caching. By leveraging rock-solid database libraries and memory-mapped files, cache performance can match and exceed industry-standard solutions. There’s no need for a C compiler or running another process. Performance is a feature and testing has 100% coverage with unit tests and hours of stress.
Features
- Pure-Python
- Fully Documented
- Benchmark comparisons (alternatives, Django cache backends)
- 100% test coverage
- Hours of stress testing
- Performance matters
- Django compatible API
- Thread-safe and process-safe
- Supports multiple eviction policies (LRU and LFU included)
- Keys support “tag” metadata and eviction
- Developed on Python 2.7
- Tested on CPython 2.7, 3.4, 3.5, 3.6 and PyPy
- Tested on Linux, Mac OS X, and Windows
- Tested using Travis CI and AppVeyor CI
Quickstart
Installing DiskCache is simple with pip:
$ pip install diskcache
You can access documentation in the interpreter with Python’s built-in help function:
>>> from diskcache import Cache, FanoutCache, DjangoCache
>>> help(Cache)
>>> help(FanoutCache)
>>> help(DjangoCache)
User Guide
For those wanting more details, this part of the documentation describes introduction, benchmarks, development, and API.
Reference and Indices
Apache2 License
A large number of open source projects you find today are GPL Licensed. A project that is released as GPL cannot be used in any commercial product without the product itself also being offered as open source.
The MIT, BSD, ISC, and Apache2 licenses are great alternatives to the GPL that allow your open-source software to be used freely in proprietary, closed-source software.
DiskCache is released under terms of the Apache2 License.
DiskCache License
Copyright 2016-2018 Grant Jenks
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
diskcache的更多相关文章
- Android开源框架:Universal-Image-Loader解析(三)DiskCache
- memoryCache 和 diskCache 的相关总结
一.缓存位置 在浏览器开发者工具的 Network 的 Size 栏会出现的三种情况: from Service Worker from memory cache from disk cache 真正 ...
- Android中常见的图片加载框架
图片加载涉及到图片的缓存.图片的处理.图片的显示等.而随着市面上手机设备的硬件水平飞速发展,对图片的显示要求越来越高,稍微处理不好就会造成内存溢出等问题.很多软件厂家的通用做法就是借用第三方的框架进行 ...
- android universal-image-loader的使用
全局配置 android-image-loader的使用 public class Application extends Application { @Override public void on ...
- 转载:Spring+EhCache缓存实例
转载来自:http://www.cnblogs.com/mxmbk/articles/5162813.html 一.ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干 ...
- 【原】iOS学习之PINCache第三方缓存框架
在项目中总是需要缓存一些网络请求数据以减轻服务器压力,业内也有许多优秀的开源的解决方案.通常的缓存方案都是由内存缓存和磁盘缓存组成的,内存缓存速度快容量小,磁盘缓存容量大速度慢可持久化. 1.PINC ...
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
转载博客:http://blog.csdn.net/xiaanming/article/details/26810303 大家好!差不多两个来月没有写文章了,前段时间也是在忙换工作的事,准备笔试面试什 ...
- android 网络加载图片,对图片资源进行优化,并且实现内存双缓存 + 磁盘缓存
经常会用到 网络文件 比如查看大图片数据 资源优化的问题,当然用开源的项目 Android-Universal-Image-Loader 或者 ignition 都是个很好的选择. 在这里把原来 ...
- ImageLoader配合ImageSwitcher的使用
先在MyApplication中初始化ImageLoader initImageLoader(getApplicationContext()); /** * 初始化ImageLoader * 如果你经 ...
随机推荐
- 【转载】sprintf()函数 和 printf()函数
sprintf()函数 和 printf()函数 参考:C++ 中的sprintf和snprintf 函数的区别 - CSDN博客 http://blog.csdn.net/youbingchen/ ...
- Java面向对象习题
1: 抛出异常:throw声明异常:throwsthrow用于在程序中抛出异常,throws用于在方法内抛出异常.throw抛出的异常没有被处理的话必须有throws有throws ,但是不一定必须有 ...
- Огонек--灯光--IPA--俄语
苏联老歌总让人沉浸其中.
- [Leetcode 392]判断子序列 Is Subsequence
[思路] 判断s是否为t的子串,所以length(s)<=length(t).于是两个指针,一次循环. 将s.t转换为数组p1.p2. i为过程中s的匹配长度. i=0空串,单独讨论返回true ...
- Nginx 自动补全url地址补全最后的斜线
参考地址: http://blog.csdn.net/dong123dddd/article/details/51660368 location /riskcontrol { root /data; ...
- ES脑裂问题
脑裂:一个集群中的不同节点对于集群的状态有了不一样的理解 ES集群的总体状态是red,本来9个节点的集群在结果中只显示4个节点在线: 正常情况下,集群中的所有节点应该对集群中的master的选择是一致 ...
- LVS+OSPF+FULLNAT集群架构
OSPF:OSPF(Open Shortest Path First开放式最短路径优先)是一个内部网关协议(Interior Gateway Protocol,简称IGP),用于在单一自治系统(aut ...
- REST easy with kbmMW #17 – Database 6 – Existing databases
kbmMW已经包含了非常精细的功能来确定和解释数据库中表的元数据. 在下一版本中,这个功能将得到进一步加强,可以导入现有数据库中的表,自动创建与表相匹配的ORM实体类. 这意味着你能够使用kbmMW的 ...
- MAVEN 阿里云中央仓库
<mirror> <id>nexus-aliyun</id> <mirrorOf>*</mirrorOf> <name>Nexu ...
- this是什么!
this 1.js的关键字指定一个对象,然后去替代他 函数内的this 函数外的this 函数内的this指向行为发生的主体 函数外的this都指向window 2.函数内的this和函数在什么 ...