Vision and roadmap
The vision
A shared cache is one of the first pieces of infrastructure a Python web app grows into, and today the choice is awkward. An in-process dict is fast, but each worker has its own copy and it’s gone on restart. Redis is shared and durable, but it’s a separate server, a network hop on every read, and one more thing to run. python-diskcache showed there’s a lot of room between those two: a cache that is just a directory, shared by every thread and process on the machine, built on SQLite. diskcache itself has had no commits since 2023, and its issues and pull requests go unanswered, so the idea needed a new home.
diskcache-oxide is a bet that this middle option can be much bigger than it has been. With a Rust engine underneath, a directory-backed cache can be fast enough to call on the event loop, safe enough for pre-forking servers and free-threaded Python, and complete enough to cover the jobs people now reach for Redis to do: caching, counters, rate limits, locks, job claims and queues. And when one machine isn’t enough, the same engine can be served over the network.
It’s being built in three stages.
Stage 1: a better diskcache (done)
Keep diskcache’s API, fix what’s wrong underneath it, and make it fast. With 0.2.3, everything from diskcache’s Cache and FanoutCache that real apps use is in. Behavior comes first: every phase keeps a conformance suite green against real diskcache 5.6.3 before chasing speed, and every deliberate difference is written down in Divergences.
Stage 2: the complete local caching toolkit (in progress)
The things a modern Python stack needs that diskcache never had. Sharding that doesn’t lock every shard for a transaction and coordination recipes that hold across every process are already in. So is a Django cache backend. Still to come are threads that scale on free-threaded Python, and an async API.
Stage 3: a cache server
The same Rust core, served over HTTP to many clients: a Redis-style central cache with SQLite underneath, for when your app outgrows one machine. A server that is the only owner of its files can run SQLite in exclusive locking mode, which keeps the WAL index in heap memory instead of a shared file. Measured on the development machine:
| Storage mode | Read | Write | Shared by several processes? |
|---|---|---|---|
WAL (the library’s mode; Python’s sqlite3, 2026-10-28) |
1.18 µs | 13.9 µs | Yes |
| WAL with exclusive locking (the server) | 0.69 µs | 16.5 µs | No, one owner |
Where things stand
Done: the core Cache
- get, set, add, delete, pop, touch, incr, decr, with expiry.
- The dictionary interface:
cache[k],k in cache,del cache[k],len(cache), iteration andreversed(). - Indexed prefix scans:
iterkeys(prefix=..., reverse=...). - Maintenance: expire(), clear(), cull(), volume(), check(), and checkpoint() for the write-ahead log.
- Least-recently-stored eviction with size_limit and cull_limit, or
eviction_policy='none'for a cache that must never drop a live entry. - Large values spilled to files, with readers that never see a spurious miss during an overwrite.
- msgpack (default) and JSON serializers with exact type tags, register_type() for your own types, and pickle only when you opt in.
- Thread-, process- and fork-safe, on GIL and free-threaded builds of 3.14 and 3.15.
- Bounded connections and memory, and a target size for the write-ahead log.
durable=True,NullCache, theCachesregistry, the CacheLike protocols andpy.typed.transact()andFanoutCache.
Done: concurrency review and soak
The concurrency core is where serious bugs hide, so it got its own phase before anyone ran it in production: independent deep reviews by several AI coding agents, model-checker tests for the lock state machines, and day-long soak runs with many processes and threads, forks, SIGKILLs and clear() under load, checking for corruption, lost writes, leaks and latency drift. The 24-hour soak passed, and it paid for itself along the way: it found the unbounded WAL growth that wal_size_limit and checkpoint() now rein in. The limit is a target, not a bound: several processes writing flat out can still take the log well past it (see Storage and WAL).
Done: the first release
0.1.2 went to PyPI after a sanitizer pass over the whole codebase (Miri, ThreadSanitizer including a free-threaded CPython built under it, AddressSanitizer and LeakSanitizer, with the bundled SQLite built under them) and a fresh 24-hour soak on the released code. It replaced diskcache at Talk Python, Python Bytes and Talk Python Training, where production latency is watched against the old numbers.
Done: parity with diskcache (0.2.3)
0.2.3 fills in what 0.1.2 left out of diskcache’s API:
- Keys of every native type:
bytes,int,float,bool,Noneand tuples, besidestr. memoizeandretry=.reversed(),pop(expire_time=True), pickling a cache, reset(), per-process stats() and check().- The coordination recipes: Lock, RLock, BoundedSemaphore, throttle, barrier, Averager and memoize_stampede.
- Tags with
evict(tag), andeviction_policy='none'. - The queue calls push, pull, peek and peekitem on Cache (see Work queues).
Tags and the eviction policy changed the on-disk format. 0.2.3 refuses a cache made by 0.1.2; since 0.3.5 such a cache opens in a versioned subdirectory instead, and remove_old_formats() cleans up the old one (see Upgrading across a format change).
Done: Windows (0.3.5)
0.3.5 adds Windows on x86_64, with wheels for all four Pythons. Everything but the fork guarantees works the same there; Getting started lists what differs. Nothing changed on disk.
Done: upgrades across a format change (0.3.5)
A release that meets a cache in another on-disk format opens a cache of its own in a versioned subdirectory and logs a warning, instead of refusing to open, so old and new workers keep running side by side during a deploy. remove_old_formats() cleans up the old cache once its workers are gone. See Upgrading across a format change.
Done: expiry that’s exact for counts and listings (0.3.5)
An entry leaves len(), iterkeys(), iter() and reversed() the moment it expires, as it always left get and in (D-060). Background maintenance, below, frees their space.
Done: background maintenance (0.3.5)
A cache looks after itself, with no expire() to schedule. One small Rust thread per process frees expired entries’ space, trims a cache left over its size limit, keeps the write-ahead log small and clears stray temporary files, for every open cache, every 5 minutes by default (maintenance_interval). The caches take turns across the interval, the processes sharing a cache take turns so eight workers don’t all do the same work, a cache with nothing to do is written only once an hour, to coordinate them (maintenance_interval=0 for none), and the thread holds the write lock only for short chunks and stops for every os.fork(). See Background maintenance.
Done: a Django cache backend (0.4.6)
'BACKEND': 'diskcache_oxide.DjangoCache' runs Django’s cache framework (the low-level API, the per-view and per-site cache, template fragments and the cache session engines) on diskcache-oxide, every worker sharing one cache on disk, with add() and incr() atomic across processes. It passes Django’s own cache tests from the source of Django 5.2, 6.0 and 6.1, on every Python each supports. See Django cache backend.
Next
In roughly this order:
- Free-threaded performance: Make throughput scale with threads on 3.14t and 3.15t. Today a cached read spends about 60% of its time in one system call SQLite makes for its shared-memory lock, and that’s the first target.
AsyncCache: An async API for asyncio frameworks that can’t slow down the sync one, includingtransact_async(). It starts as an experiment and ships only if it earns its place; if it doesn’t, this page will say why.- Network server: Stage 3, above. Speculative, and a separate product if it happens.
Decided against, and why
- Least-recently-used and least-frequently-used eviction. diskcache implements them by writing to the database on every get. Reads that never write are what let many processes read at once without queueing, so these stay out unless a design keeps reads write-free. Least-recently-stored stays the default, and
eviction_policy='none'turns eviction off. DequeandIndex, until someone asks. If you need one, open an issue. AnIndexis only as general as the key types, and both default to a temporary directory, which diskcache-oxide doesn’t do.disk=andDisksubclasses. A Python class on every read and write would undo the Rust engine;serializer=and register_type() cover what people used them for.- Pickled keys. Keys are never pickled, so listing keys never runs pickle and a key’s identity doesn’t depend on pickle’s bytes.
read=Trueandread()(streaming a file in and out). Folded into the large-file cache idea below.- Persisted statistics. stats() counts per process, in memory, because diskcache’s persisted counters make every get a write.
Further out
Ideas being considered, not yet committed to:
- A large-file cache, handing out an open file rather than a path, which is where diskcache’s
read=Truewould fit. - Encryption at rest, if a real need appears: SQLCipher for the database, authenticated encryption for spill files.
Non-goals
- Reading existing diskcache directories. diskcache-oxide uses its own on-disk format, so caches start cold when you switch.
- A module named
diskcache(it would collide with the real package). - diskcache’s own DjangoCache class, ported. diskcache-oxide has a Django backend of its own instead, above.
- Python older than 3.14.