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.0.1.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.0.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sieve_cache-0.0.1.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.0.1.tar.gz
Algorithm Hash digest
SHA256 5910bdf60b3dc579f477b3108312f96b3fa7d81a1bb87d7c8cffb3f6cb1720ac
MD5 be81cd4d8422de35a01db0f2bc473a49
BLAKE2b-256 9bb075002867173427f8211ad4ed9dbcce0d6c86f74f7643025bca3a0536b7d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for sieve_cache-0.0.1.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.0.1-py3-none-any.whl.

File metadata

  • Download URL: sieve_cache-0.0.1-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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e0ae62213e713b9b8ae0822e572d64ba78e09fbc0b5e932caa33f87111fc8b20
MD5 15ebf169656a6c858628d6a79dfde8aa
BLAKE2b-256 00f170757a645d27d45541c4170c09e44d354d94379cdc0ffcdd0f7722257fff

See more details on using hashes here.

Provenance

The following attestation bundles were made for sieve_cache-0.0.1-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