Skip to main content

A high-performance Python library providing bucket-based rotating data structures with approximate TTL eviction and strict memory constraints.

Project description

RoTTL — Rotating TTL Data Structures

RoTTL provides memory-efficient rotating sets, dicts, and Bloom filters with approximate TTL-based eviction.

Rather than maintaining per-item expiry timestamps, the TTL window is divided into a fixed number of rotating buckets — expired buckets are evicted as a whole, trading per-item precision for significantly lower memory usage and faster writes, at the cost of sequentially scanned lookups.

The library exposes three structures:

  • RotatingTTLSet — a rotating, TTL-based set backed by native Python set buckets.
  • RotatingTTLDict — a rotating, TTL-based dict backed by native Python dict buckets.
  • RotatingTTLBloom — a rotating, TTL-based Bloom filter backed by rbloom.

RotatingTTLSet and RotatingTTLDict support an optional history fast-reject mode, which maintains an auxiliary Bloom filter over all non-expired historical buckets. This allows most membership misses to be short-circuited without scanning the full bucket deque, at the cost of filter rebuild on each rotation.

RotatingTTLSet and RotatingTTLDict rotate automatically on both time and capacity. RotatingTTLBloom rotates automatically only by time, because estimating the number of items in a Bloom filter requires counting all set bits, which is too expensive to do on every insertion. Instead, maybe_rotate_by_saturation() can be called manually to check if the active bucket has exceeded its capacity, and if so — trigger rotation (to enforce the configured FPR).


When to use RoTTL

  • Approximate TTL is acceptable. Expiry happens at bucket boundaries, not per item. Under normal load (no capacity-based eviction), items live between ttl - (ttl / num_buckets) and ttl seconds. Capacity pressure can cause earlier eviction.
  • Memory-constrained environments. RotatingTTLSet and RotatingTTLDict use roughly 3–4× less memory than cachetools.TTLCache at all tested capacities. RotatingTTLBloom can reduce memory even further, depending on the configured bucket_fpr and num_buckets.
  • Write-heavy workloads. RoTTL's write path avoids the expensive per-item bookkeeping required for exact TTL, making it 6–15x faster than cachetools.TTLCache (varies by usage of fast-reject and rotation pressure).
  • Lookup performance scales with configuration. Lookups scan up to num_buckets buckets, so with a small bucket count the overhead is negligible. With a large bucket count, hit cost depends on which bucket the item is found in, and miss cost grows linearly. RotatingTTLSet and RotatingTTLDict's history fast-reject option makes most miss latency independent of num_buckets, at the cost of slower rotations.

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

rottl-0.0.2.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

rottl-0.0.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file rottl-0.0.2.tar.gz.

File metadata

  • Download URL: rottl-0.0.2.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rottl-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4da6fb700bb98d399696de2b5ea8ca7e4050da2c6b5bd2ba97a2ccb4bf11e42f
MD5 9ec011068cbcea3378476ccb335ec2d4
BLAKE2b-256 d4364bd0622807d0ef14ac9cb4b6805056fa74ceba3beaf621e8c9a60fe8b098

See more details on using hashes here.

Provenance

The following attestation bundles were made for rottl-0.0.2.tar.gz:

Publisher: python-publish.yml on sharvul/rottl

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

File details

Details for the file rottl-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: rottl-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rottl-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19060b06d170182a89e75562cebf34d9116724767815179582c19f834ee6730e
MD5 fe239de753cfe18d936b615817f2477d
BLAKE2b-256 9b67aea8f8a2a563eff71d09f9d5dc806e03d28e91adcf32ff5a9ed5c64488a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for rottl-0.0.2-py3-none-any.whl:

Publisher: python-publish.yml on sharvul/rottl

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