Repository navigation
diskcache-oxide 0.2.3
Delete your caches when you upgrade. This release changes the on-disk format (format 3, for tags and the eviction policy). Opening a cache made by 0.1.2 raises FormatMismatchError, naming the database: stop every process using the cache, delete its directory (a FanoutCache's whole root, never one shard), and it's recreated empty on the next open. 0.1.2 refuses a format-3 cache the same way, and neither version writes anything into the other's. A 0.1.2 worker still running when its cache is deleted and recreated can't change the new one either: once it opens the new file, its writes, deletes and maintenance calls fail with "no such table" (only a touch gets through), because format 3 renames the table they all use.
Added
- Keys of every native type:
bytes,int(64-bit),float,bool,None, and tuples of those, nested up to 32 deep, besidestr. They're never pickled and compare by exact type, so1,1.0andTrueare three keys.iterkeys()listsstrkeys first, then the other types in a fixed order;iterkeys(prefix=...)listsstrkeys only. A FanoutCache routes every key type. Type checkers seediskcache_oxide.Key. memoize(name=None, typed=False, expire=None, tag=None, ignore=())onCache,FanoutCacheandNullCache, as diskcache's, with the same keys, sof.__cache_key__(...)returns the tuple diskcache would. Every argument must be a key type, checked before the function runs;typed=Truestores type names.MemoizedandMemoizertype the wrapper.CorruptKeyError, aCorruptValueError, raised by iteration that meets a stored key it can't read (a damaged page or file); it never skips one.reversed(cache),pop(key, expire_time=True), a read-onlydurableattribute, andreset(key, value)to read or persistsize_limit,cull_limitandeviction_policy(aFanoutCachesplits asize_limittotal across its shards), onCache,FanoutCacheandNullCache.- Pickling a
CacheorFanoutCache: it reopens the directory with the options the handle was opened with, in another process too. ATypeRegistrypickles (the global one by reference). stats(enable=True, reset=False): hit and miss counts ofget, per process and in memory, so agetnever writes.check(fix=False, retry=False): the database and value files against each other, as diskcache's, in short steps;fix=Trueremoves entries whose files are missing or cut short and old orphan files, sweeps empty folders, corrects the totals andVACUUMs.UnknownFileWarningandEmptyDirWarning.- The coordination recipes
Lock,RLock,BoundedSemaphore,Averager,throttle,barrierandmemoize_stampede, as diskcache's, refusing aNullCacheordurable=Truecache, withthrottle's two diskcache bugs fixed. See the new Coordination guide page. - Tags:
tag=(keyword-only) onsetandadd, any key type, compared by exact type, andtag=Trueongetandpop, returning diskcache's(value, tag)and(value, expire_time, tag)tuples.evict(tag, *, timeout=None, retry=False)onCache,FanoutCacheandNullCacheremoves every entry with that tag stored before the call, in chunks likeclear().memoize(tag=...)and the recipes'tag=tag what they store. An overwrite withouttag=leaves the entry untagged;addon a live key,touchandincrkeep its tag. eviction_policy='least-recently-stored'(the default) or'none'onCacheandFanoutCache, stored in the cache and read inside every write, so a change from one process applies to all at their next write. Under'none'nothing is evicted for size, expired entries are still removed, andcull()returns how many it removed.'least-recently-used'and'least-frequently-used'raiseValueError. A read-onlyeviction_policyattribute.- The queue calls
push,pull,peekandpeekitemonCacheandNullCache, with diskcache's signatures and return shapes (expire_time=,tag=,retry=keyword-only). Each item goes to exactly one puller across every process;pulldecodes before it deletes, so an item this process can't read stays queued;peekandpeekitemnever write. A queue's items are only keys of its exact shape, andpushraisesOverflowErrorrather than overwrite a key. See the new Work queues recipe. ENOVALandUNKNOWN, diskcache's sentinels.retry=True(keyword-only) onget,set,add,delete,pop,touch,incr,decr,expire,cull,clearandevict: this cache's ownTimeoutis retried until the call gets through, even on adurable=Truehandle; one raised by your code (a hook, aclock) is not. A retriedexpire,cull,clearorevictreturns everything it removed.
Changed
- Iterating a cache is typed
Iterator[Key]rather thanIterator[str], since keys can now be other types;iterkeys(prefix=...)is stillIterator[str]. Type-checked code that treats every iterated key as astrneeds a narrowing (isinstance(key, str)). - The
TypeErrorfor a key of the wrong type now names the types that are accepted. TransactionalCacheLikegainedpush,pull,peekandpeekitem(notCacheLike:FanoutCachehas no queue calls).CacheLikegainedmemoize,stats,check,reset,evict,durable,eviction_policyand__reversed__,getandpoptheirtag=(andpopitsexpire_time=), andsetandaddtheirs; a fake typed against it needs them too.transact(retry=True)sleeps between attempts instead of retrying at once, so atimeout=0cache doesn't spin.
Wheels: macOS arm64 and Linux (manylinux_2_28) aarch64 and x86_64, for CPython 3.14, 3.14t, 3.15 and 3.15t, profile-guided. Checksums are in SHA256SUMS. Full changes: CHANGELOG.md, v0.1.2...v0.2.3.