Repository navigation
diskcache-oxide 0.4.6
No format change: caches made by 0.3.5 open as they are.
A Django cache backend. 'BACKEND': 'diskcache_oxide.DjangoCache' runs Django's cache framework on diskcache-oxide: the low-level API, the per-view and per-site cache, template fragments and the cache session engines, with every worker process sharing one cache on disk and add() and incr() atomic across processes. It passes Django's own cache tests (BaseCacheTests, the middleware, template-response and i18n tests, and the cache and cached_db session tests) from the source of Django 5.2, 6.0 and 6.1, on Python 3.14 and 3.14t, and 6.1 on 3.15 and 3.15t. OPTIONS takes Cache's keywords by their own names, and shards makes the alias a FanoutCache. Its defaults differ from Cache's where Django needs them to: a 1.0 s lock wait, and pickle=True, since Django caches responses, SafeStrings and model instances. Errors raise unless OPTIONS['durable'] is set; a durable alias for the cache or cached_db session engine is refused. See the new Django cache backend page.
Added
diskcache_oxide.DjangoCache, loaded on first use, soimport diskcache_oxidestill never imports Django. Beyond Django's API it hastag=onsetandadd,evict(tag),pop,expire(),cull(),stats(),maintenance_stats(),check()andcache, theCacheunderneath;diskcache_oxide.djangocache.close_all()releases every handle it opened (it runs by itself whenoverride_settingschangesCACHES).- The
djangoextra,pip install 'diskcache-oxide[django]', which asks for Django 5.2 or newer. examples/django/, a Django project on two aliases (pages durable, sessions and counters plain) under gunicorn, with its tests.
Fixed
- A value holding a lone surrogate inside it, such as
{'q': '\ud800'}(one can arrive in a JSON body and end up in a session), is now pickled underpickle=True, as diskcache stores it, instead of raisingUnicodeEncodeErroratset. Without pickle it still raises, and a lone surrogate in a top-levelstrstill raises either way, as it does in diskcache. Values the serializer could already store are written exactly as before.
Documentation
- An "Example apps" section: walkthroughs of the FastAPI example (
examples/webapp) and the Django example (examples/django), file by file. - The Django page has measured numbers: reads, writes, worker processes and threads against diskcache's backend and Django's own
FileBasedCache,DatabaseCacheandLocMemCache(bench/django.py), and whyagethops to a thread though the read is faster than the hop. - Corrected: a plain
Cacheslowing past two or three worker processes isn't the write lock. It happens with no writes at all (bench/read_procs.py: 836k ops/s at 2 processes, 296k at 8), most likely SQLite's shared-memory read lock.FanoutCacheis now recommended for a cache several worker processes use heavily, reading or writing, not only one they write to; one worker process doesn't need it. - A lone surrogate and an int past Python's 4,300-digit limit are documented: the first falls back to pickle inside a value, the second always raises (D-063).