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
- Web Applications: Manage different caches for user sessions, API responses, and static content with context-specific eviction policies.
- Data Processing Pipelines: Use specialized caches for different stages of data processing to optimize performance and resource usage.
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file awarecache-1.4.0.tar.gz.
File metadata
- Download URL: awarecache-1.4.0.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba2d2870e882cb3213ae4e2c5c0d0c5fe75025613527735ddac8e66a6c5015d9
|
|
| MD5 |
8065fd219634cd1a445288435ea4a0b7
|
|
| BLAKE2b-256 |
18c9c129df445720388b2982229c77df55b1d296c6ba587826a5027fb9e14f82
|
File details
Details for the file awarecache-1.4.0-py3-none-any.whl.
File metadata
- Download URL: awarecache-1.4.0-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.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60c58a1207ae65786188b8468cb27d60a613a7154f9ead714ce192cce669385b
|
|
| MD5 |
0f698b52d99d93361f47a7f1ffeefabe
|
|
| BLAKE2b-256 |
c926cf6dede71d9b72a19a418f298e58cd726c354909199d667cbd6d70d38891
|