Skip to main content

A context-aware caching library with customizable policies and metrics.

Project description

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.

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

awarecache-1.5.8.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

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

awarecache-1.5.8-py3-none-any.whl (2.2 kB view details)

Uploaded Python 3

File details

Details for the file awarecache-1.5.8.tar.gz.

File metadata

  • Download URL: awarecache-1.5.8.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for awarecache-1.5.8.tar.gz
Algorithm Hash digest
SHA256 b7b953fa9b9a2dd4b5c4717af0c76a25de4c1f9fb6a6d753d032e318a72b6d67
MD5 5d7a1962400f2b4165c4df79fe333b73
BLAKE2b-256 e9030bc56311099a146a769aa5c92d901d741e78cbdb2eef135a13f7c66f4f4e

See more details on using hashes here.

File details

Details for the file awarecache-1.5.8-py3-none-any.whl.

File metadata

  • Download URL: awarecache-1.5.8-py3-none-any.whl
  • Upload date:
  • Size: 2.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for awarecache-1.5.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e8a44bc75c8dfda5954058d62438a7b11491126060270b164a8a0986435b888a
MD5 95091ed922b2c67c54decd0abbb45cef
BLAKE2b-256 8611d7817df3e9f3973f7e4aae4297547dd05e9b9c24380ffe79e77a9ec2bb80

See more details on using hashes here.

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