Skip to main content

A simple implementation of SIEVE caching algorithm

Project description

sieve.cache

sieve.cache is a lightweight Python cache utility that implements the SIEVE eviction algorithm on top of dogpile.cache backends.

Project Summary

  • Implements a Sieve cache with a decorator-based API.
  • Uses a doubly linked list (head, tail, hand) to track entries.
  • Applies SIEVE eviction using a visited bit on each node.
  • Integrates with dogpile.cache regions and key generation.
  • Includes an in-memory backend adapter (sieve_cache.memory).

How It Works

When a decorated function is called:

  1. A cache key is generated from function arguments.
  2. If the key exists, the node is marked as visited and returned.
  3. On a miss, the function is executed and result cached.
  4. 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.

Installation

Install from source:

pip install sieve.cache

Quick Usage

import 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))  # cached

Project Layout

  • sieve_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-memory dogpile.cache backend.
  • sieve_cache/__init__.py: Region/backend configuration and factory helpers.

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sieve_cache-0.1.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sieve_cache-0.1.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file sieve_cache-0.1.0.tar.gz.

File metadata

  • Download URL: sieve_cache-0.1.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sieve_cache-0.1.0.tar.gz
Algorithm Hash digest
SHA256 27b8faf391936d3ab366cf642b343e6e62a748ace620e0ccedee7054199f3474
MD5 15e9809e6778a7b8299b48f079f9c899
BLAKE2b-256 c3315376ec7d171cc6966a440042f3b73c4344e500fc82add09f80c0457fe47c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sieve_cache-0.1.0.tar.gz:

Publisher: release-pypi.yml on daipham3213/sieve.cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sieve_cache-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sieve_cache-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sieve_cache-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 694c89ac832f9845f1dfa229c84243f292c23939fb943e57bcba76f6f3cad66d
MD5 41a53f1c5ccdcd8c6ac9ec1d284f6b8e
BLAKE2b-256 148f4d3bfbbcd0226475bfcbb4c0e4dcfc74db664af35a305af3789d996af699

See more details on using hashes here.

Provenance

The following attestation bundles were made for sieve_cache-0.1.0-py3-none-any.whl:

Publisher: release-pypi.yml on daipham3213/sieve.cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page