diskcache-community
Disk and file backed persistent cache for Python, built on SQLite
[Tutorial] - [API] - [Benchmarks] - [Docs] - [Changelog]
Install
pip install diskcache-community
The package is imported as diskcache_community and never touches the
upstream diskcache package, so both can be installed in the same environment;
see Migrating from diskcache.
Usage
from diskcache_community import Cache
cache = Cache('cache') # the directory is created with mode 0700
cache.set('answer', 42, expire=3600, tag='math')
cache['config'] = {'debug': False}
cache.get('answer') # 42
cache.get('missing', default=None)
cache.evict('math') # delete every key tagged 'math'
Memoize function results across processes and restarts:
@cache.memoize(expire=600, ignore={'session'})
def fetch(url, session):
return session.get(url).text
Shard across several SQLite files for higher write throughput, and plug the same cache into Django:
from diskcache_community import FanoutCache
cache = FanoutCache('cache', shards=8, timeout=1)
# settings.py
CACHES = {
'default': {
'BACKEND': 'diskcache_community.DjangoCache',
'LOCATION': '/var/tmp/django_cache',
'SHARDS': 8,
'DISK': 'diskcache_community.SafeDisk', # restricted unpickling, see below
}
}
Caches shared with untrusted writers should use SafeDisk, which unpickles
only a fixed set of built-in types and keeps file reads inside the cache
directory:
from diskcache_community import Cache, SafeDisk
cache = Cache('cache', disk=SafeDisk)
Fix CVE-2025-69872 in diskcache covers caches that libraries create for you, your own classes, and entries already in the cache.
Features
Cache,FanoutCacheandDjangoCachefor key-value caching with expiry, tags, size limits and LRU, LFU and other eviction policiesDequeandIndex: persistent, cross-processcollections.dequeanddict- Recipes for memoization with stampede prevention, cross-process locks, semaphores and throttling
- Thread-safe and process-safe, with fork-safe connection handling
- Read-only mode, automatic when the directory is not writable
- Opt-in
SafeDiskfor caches whose directory other users can write to - Pure Python on top of the standard library
sqlite3; no server, no compiler - Tested on CPython 3.10 to 3.14 on Linux, macOS and Windows
- Gets in about 2.6 µs and sets in about 19 µs on an Apple M5 Pro in the benchmarks against memcached, Redis, lmdb, sqlitedict and shelve; sets are 9 to 14 % faster than in diskcache 5.6.3, and twice as fast for 1 MB values
Why this fork
The upstream project stopped releasing after 5.6.3 (August 2023) and its last
commit landed in March 2024. In 2025, CVE-2025-69872 was published against
every released version: the cache reads pickled values with pickle.load, so
anyone who can write into the cache directory can run code in the process
that reads from it. The package still works, but scanners flag it and there
is no fixed upstream version.
This fork publishes the same library as diskcache-community. It keeps the
cache.db schema, the file layout, the serialization modes and the memoize
key format unchanged, so a 5.6.3 process opens a directory written by this
fork and the reverse. It adds the opt-in SafeDisk, creates cache directories
with mode 0700, opens read-only directories read-only, closes the per-thread
SQLite connections it used to leak, and survives fork. The package is
imported as diskcache_community, so a project can move to it while other
dependencies in the same environment still use the upstream diskcache.
The changelog lists every change and
SECURITY.md describes what is and is not fixed.
DiskCache was written and maintained by Grant Jenks from 2016 to 2023. This fork keeps his license, copyright and author credit; see NOTICE.
Migrating from diskcache
The public API and the files on disk are unchanged; only the import name differs. Install the fork and change the imports:
pip install diskcache-community
import diskcache_community as diskcache # was: import diskcache
from diskcache_community import Cache # was: from diskcache import Cache
In Django settings, use 'diskcache_community.DjangoCache' and
'diskcache_community.SafeDisk'. Existing cache directories open as they
are, and a 5.6.3 process still opens directories written by the fork.
The migration guide lists the few behaviour changes since 5.6.3 and how to go back.
The upstream diskcache package can stay installed, for example when another
dependency requires it. Each library uses the package it imports. A library
that wants to support both can import whichever is present:
try:
import diskcache_community as diskcache
except ImportError:
import diskcache
Documentation
The documentation is at diskcache-community.readthedocs.io:
- Fix CVE-2025-69872 in diskcache
- Migrating from diskcache 5.6.3
- Tutorial
- API reference
- Benchmarks against memcached, Redis, lmdb, sqlitedict and shelve, the Django cache backends, and diskcache 5.6.3 (measured 2026-10-12)
- Old benchmarks from 2019, measured by upstream for version 4: Cache and DjangoCache
- Comparisons with other key-value stores and caching libraries
- Case studies: web crawler, landing page caching
- Development
Comparison
| diskcache | dbm | shelve | sqlitedict | pickleDB | |
|---|---|---|---|---|---|
| Atomic | Always | Maybe | Maybe | Maybe | No |
| Thread-safe | Yes | No | No | Yes | No |
| Process-safe | Yes | No | No | Maybe | No |
| Eviction | LRU, LFU, more | None | None | None | None |
| Serialization | Customizable | None | Pickle | Customizable | JSON |
| Data types | Mapping, deque | Mapping | Mapping | Mapping | Mapping |
The full comparisons page covers features, quality and timings in detail.
Contributing and security
Bug reports and pull requests are welcome on GitHub. CONTRIBUTING.md explains the compatibility contract and how to run the tests. Report vulnerabilities privately as described in SECURITY.md.
License
Copyright 2016-2023 Grant Jenks. Modifications in this fork are copyright 2026 diskcache-community contributors. Licensed under the Apache License, Version 2.0.
Metadata
Release files for diskcache-community 5.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| diskcache_community-5.8.1.tar.gz | 110.8 kB | With provenance | Details for diskcache_community-5.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| diskcache_community-5.8.1-py3-none-any.whl | Python 3 | none | any | Details for diskcache_community-5.8.1-py3-none-any.whl |
Total release size: 182.8 kB
Release files / diskcache_community-5.8.1.tar.gz
| Download URL | diskcache_community-5.8.1.tar.gz |
|---|---|
| Size | 110.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b780ed4b8381487c53cc778599f745784391c4c7af23c528ece049e008be6197
|
|
BLAKE2b-256 checksum How to use checksums |
9ab1ef17a29956f0208c5acbc30247c742739d37135531a0facf26a5752f9382
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / diskcache_community-5.8.1-py3-none-any.whl
| Download URL | diskcache_community-5.8.1-py3-none-any.whl |
|---|---|
| Size | 72.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4c18c3fec2451154f768764f0f3e97fdddfb2bb4fcff8754fc28fcc88ca1b2ea
|
|
BLAKE2b-256 checksum How to use checksums |
b85482c3738aceba6f4687ba6c808970dbf1036581616e43ef69da6fbfdcd4ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logSecurity for diskcache-community 5.8.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for diskcache_community-5.8.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.