Skip to main content

AwareCache

awarecache is a versatile caching library that provides context-aware caching with customizable eviction policies and detailed cache metrics. It allows you to manage different caches for different contexts with various caching strategies, and track performance metrics such as cache hits and misses.

Features

  • Context-Aware Caching: Manage different caches for different contexts.
  • Customizable Eviction Policies: Choose from LRU, LFU, MRU, FIFO, TinyLFU, SLRU, and Clock caching strategies.
  • Cache Metrics: Track cache performance with hit and miss statistics.

Use Cases

  1. Web Applications: Manage different caches for user sessions, API responses, and static content with context-specific eviction policies.
  2. Data Processing Pipelines: Use specialized caches for different stages of data processing to optimize performance and resource usage.
  3. Microservices: Maintain separate caches for different services or components, each with its own eviction strategy.

Installation

You can install awarecache via pip:

pip install awarecache

Usage

Basic Example

Here's a quick example to get you started:

from awarecache import Cache

# Create a Cache instance with default LRU policy and a capacity of 100
cache = Cache()

# Set context-specific policies
cache.set_context_policy('user_sessions', 'LRU', capacity=50)
cache.set_context_policy('api_responses', 'LFU', capacity=200)

# Add and retrieve items from the 'user_sessions' cache
cache.put('session1', 'data1', context='user_sessions')
print(cache.get('session1', context='user_sessions'))  # Output: data1

# Add and retrieve items from the 'api_responses' cache
cache.put('response1', 'data2', context='api_responses')
print(cache.get('response1', context='api_responses'))  # Output: data2

# Get cache performance metrics
print(cache.get_metrics())  # Output: {'hits': 2, 'misses': 0}

Supported Eviction Policies

  • LRU (Least Recently Used): Removes the least recently accessed item.
  • LFU (Least Frequently Used): Removes the least frequently accessed item.
  • MRU (Most Recently Used): Removes the most recently accessed item.
  • FIFO (First In, First Out): Removes the oldest item.
  • TinyLFU: A variant of LFU that uses a probabilistic approach for cache eviction.
  • SLRU (Segmented LRU): Combines LRU with a segmented approach to differentiate between frequently and infrequently accessed items.
  • Clock: A circular buffer approach to manage cache items with a clock-like replacement strategy.

Metadata

Release files for awarecache 1.5.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for awarecache 1.5.12
File Size Uploaded Provenance
awarecache-1.5.12.tar.gz 6.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for awarecache 1.5.12
File Interpreter ABI Platform
awarecache-1.5.12-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / awarecache-1.5.12.tar.gz

Download URL awarecache-1.5.12.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
986ba8db9954112b2fee2ba3ec1effbe04a828aa54907afe5a4b75c432779e59
BLAKE2b-256 checksum
How to use checksums
c05656eff0edf5c444f30497853db4a0d8b6f48f4bbe5e6cdf7069a2d73f2263
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / awarecache-1.5.12-py3-none-any.whl

Download URL awarecache-1.5.12-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
033ad204a7e9b9eac713bc1a35a9db004b26cc8ad074c6f206d9edb3639f2e15
BLAKE2b-256 checksum
How to use checksums
6ffac9a8e3b276f552feda995bba01f1a3cca3be77cffae9884f726c9edc284b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Security for awarecache 1.5.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page