sieve.cache is a lightweight Python cache utility that implements the
SIEVE eviction algorithm on top of dogpile.cache backends.
- Implements a
Sievecache with a decorator-based API. - Uses a doubly linked list (
head,tail,hand) to track entries. - Applies SIEVE eviction using a
visitedbit on each node. - Integrates with
dogpile.cacheregions and key generation. - Includes an in-memory backend adapter (
sieve_cache.memory).
When a decorated function is called:
- A cache key is generated from function arguments.
- If the key exists, the node is marked as visited and returned.
- On a miss, the function is executed and result cached.
- If cache size reaches
max_size, an item is evicted by SIEVE.
The eviction pointer (hand) scans backward, clears visited=True nodes,
and removes the first unvisited candidate.
Install from source:
pip install sieve.cacheimport sieve_cache
cache = sieve_cache.create_sieve(backend="sieve_cache.memory")
@cache.cache(max_size=128)
def expensive_call(x: int) -> int:
return x * x
print(expensive_call(5))
print(expensive_call(5)) # cachedsieve_cache/sieve.py: Core SIEVE cache implementation and decorator.sieve_cache/node.py: Cache node model used by linked-list structure.sieve_cache/backends/memory.py: In-memorydogpile.cachebackend.sieve_cache/__init__.py: Region/backend configuration and factory helpers.