Skip to main content

ShardedCacheLike

A CacheLike with a sharded cache’s transact(*, key, retry=False), which FanoutCache and

Usage

Source

ShardedCacheLike()

NullCache both have.

On a FanoutCache, with cache.transact(key='total') as tx: runs the block’s calls on this thread for keys on key‘s shard in one write transaction, and refuses keys on other shards (ValueError); tx is the cache. On a NullCache it’s a no-op that yields the NullCache. key is keyword-only, so transact('total') is a type error rather than a retry of ’total’.

Examples

from diskcache_oxide import ShardedCacheLike

def bump(cache: ShardedCacheLike, key: str) -> None:
    with cache.transact(key=key) as tx:
        tx.set(key, tx.get(key, 0) + 1)

Methods

Name Description
transact() A context manager holding a write transaction on key’s shard for the block, yielding the cache.

transact()

A context manager holding a write transaction on key’s shard for the block, yielding the cache.

Usage

Source

transact(*, key, retry=False)