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.

Testimonials

Does your company or website use DiskCache? Send us a message and let us know.

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.

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

http://www.apache.org/licenses/LICENSE-2.0

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的更多相关文章

  1. Android开源框架:Universal-Image-Loader解析(三)DiskCache

  2. memoryCache 和 diskCache 的相关总结

    一.缓存位置 在浏览器开发者工具的 Network 的 Size 栏会出现的三种情况: from Service Worker from memory cache from disk cache 真正 ...

  3. Android中常见的图片加载框架

    图片加载涉及到图片的缓存.图片的处理.图片的显示等.而随着市面上手机设备的硬件水平飞速发展,对图片的显示要求越来越高,稍微处理不好就会造成内存溢出等问题.很多软件厂家的通用做法就是借用第三方的框架进行 ...

  4. android universal-image-loader的使用

    全局配置 android-image-loader的使用 public class Application extends Application { @Override public void on ...

  5. 转载:Spring+EhCache缓存实例

    转载来自:http://www.cnblogs.com/mxmbk/articles/5162813.html 一.ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干 ...

  6. 【原】iOS学习之PINCache第三方缓存框架

    在项目中总是需要缓存一些网络请求数据以减轻服务器压力,业内也有许多优秀的开源的解决方案.通常的缓存方案都是由内存缓存和磁盘缓存组成的,内存缓存速度快容量小,磁盘缓存容量大速度慢可持久化. 1.PINC ...

  7. Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用

    转载博客:http://blog.csdn.net/xiaanming/article/details/26810303 大家好!差不多两个来月没有写文章了,前段时间也是在忙换工作的事,准备笔试面试什 ...

  8. android 网络加载图片,对图片资源进行优化,并且实现内存双缓存 + 磁盘缓存

    经常会用到 网络文件 比如查看大图片数据 资源优化的问题,当然用开源的项目  Android-Universal-Image-Loader  或者 ignition 都是个很好的选择. 在这里把原来 ...

  9. ImageLoader配合ImageSwitcher的使用

    先在MyApplication中初始化ImageLoader initImageLoader(getApplicationContext()); /** * 初始化ImageLoader * 如果你经 ...

随机推荐

  1. ActiveMQ的P2P示例

    ActiveMQ的P2P示例(点对点通信) (1)下载安装activemq,启动activeMQ. 详细步骤参考博客:http://www.cnblogs.com/DFX339/p/9050878.h ...

  2. 读书笔记 C#事件event浅析(一)

    在C#中,所谓event事件,就是一种特殊的委托.如果要声明事件,首先就要声明一个相对应的委托类型.按照流程来说,事件相当于委托类型往上升了一级似的,我是这样认为的. //1.先声明委托类型 publ ...

  3. jdk8-全新时间和日期api

    1.jdk8日期和时间api是线程安全的 1.java.time  处理日期时间 2.java.time.temporal: 时间校正器.获取每个月第一天,周几等等 3.java.time.forma ...

  4. 关于MEX函数的说明

    reference:http://www.mathworks.com/help/matlab/ref/mex.html .MEX文件是一种可在matlab环境中调用的C(或fortran)语言衍生程序 ...

  5. jvm内存配置参数

    请看下面题目: 对于jvm内存配置参数: -Xmx10240m -Xms10240m -Xmn5120m -XXSurvivorRatio=3 其最小内存值和Survior区总大小分别是: a. 51 ...

  6. Flask源码阅读-第四篇(flask\app.py)

    flask.app该模块2000多行代码,主要完成应用的配置.初始化.蓝图注册.请求装饰器定义.应用的启动和监听,其中以下方法可以重点品读和关注 def setupmethod(f): @setupm ...

  7. 句柄线程做参数和PostMessage的用法

    当我们启动一个线程,并且要给线程函数传递的参数是窗口句柄时,我们应该这样做: HWND hHwnd = GetSafeHwnd(); HANDLE hThread; DWORd dwThreadId; ...

  8. LeetCode--219、268、283、414、448 Array(Easy)

    219. Contains Duplicate II Given an array of integers and an integer k, find out whether there are t ...

  9. nodejs环境下配置运行mysql

    首先需要在本地运行node环境   必须在本地安装mysql(可以用xampp里面的) 在node环境下引入mysql模块   命令: npm install node-mysql 运用例子(前提条件 ...

  10. 内存直读技术DMA

    DMA(Direct Memory Access) DMA(Direct Memory Access)即直接存储器存取,是一种快速传送数据的机制. 工作原理 DMA是指外部设备不通过CPU而直接与系统 ...