https://github.com/saviornt/cachemanager
A flexible caching system that supports both local file-based caching (using shelve) and Redis-based caching.
https://github.com/saviornt/cachemanager
cache cache-control cache-management cache-storage caching python
Last synced: 9 months ago
JSON representation
A flexible caching system that supports both local file-based caching (using shelve) and Redis-based caching.
- Host: GitHub
- URL: https://github.com/saviornt/cachemanager
- Owner: saviornt
- Created: 2025-03-19T00:16:31.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-03-22T05:43:00.000Z (10 months ago)
- Last Synced: 2025-04-09T17:11:22.788Z (9 months ago)
- Topics: cache, cache-control, cache-management, cache-storage, caching, python
- Language: Python
- Homepage:
- Size: 5.34 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CacheManager
A flexible and extensible caching solution for Python applications supporting multiple cache layers, eviction policies, and advanced features.
## Features
- **Multilayer Caching**: Combine memory, Redis, and disk caching for optimal performance
- **Configurable Eviction Policies**: LRU, LFU, and FIFO implementations
- **Advanced Caching Strategies**:
- Compression for efficient storage
- Namespacing for logical separation
- Telemetry for monitoring cache performance
- Security features for data protection
- Resilience mechanisms
- **Decorator-based Caching**: Easily cache function results
- **Bulk Operations**: Efficient handling of multiple cache items
- **Extensive Configuration Options**: Fine-tune cache behavior for your needs
## Installation
```bash
pip install git+https://github.com/saviornt/cachemanager
```
## Quick Start
```python
from src.cache_manager import CacheManager
from src.cache_config import CacheConfig
# Create a cache configuration
config = CacheConfig(
cache_ttl=300, # 5 minutes TTL
eviction_policy='LRU', # Use Least Recently Used eviction
memory_cache_enabled=True, # Enable in-memory caching
disk_cache_enabled=True, # Enable disk caching
cache_dir='./cache' # Location for disk cache
)
# Initialize cache manager
cache = CacheManager(config)
# Set a value in the cache
cache.set('key1', 'value1')
# Get a value from the cache
value = cache.get('key1')
# Use the caching decorator
@cache.cached()
def expensive_operation(param):
# Expensive computation here
return result
# Call the function - result will be cached
result1 = expensive_operation('param1')
result2 = expensive_operation('param1') # Returns cached result
```
## Advanced Usage
### Hybrid Caching
```python
from src.cache_config import CacheConfig, CacheLayerConfig, CacheLayerType
# Configure multiple cache layers
config = CacheConfig(
use_layered_cache=True,
cache_layers=[
CacheLayerConfig(type=CacheLayerType.MEMORY, ttl=60), # 1 minute in memory
CacheLayerConfig(type=CacheLayerType.REDIS, ttl=300), # 5 minutes in Redis
CacheLayerConfig(type=CacheLayerType.DISK, ttl=3600) # 1 hour on disk
]
)
# Initialize cache manager with layered caching
cache = CacheManager(config)
```
### Data Compression
```python
# Enable compression for large objects
config = CacheConfig(
enable_compression=True,
compression_min_size=1024, # Compress objects larger than 1KB
compression_level=6 # Compression level (1-9)
)
cache = CacheManager(config)
```
## Contributing
Contributions are welcome! Please see [Contributing Guide](docs/build/html/contributing.html) for details.
## License
This project is licensed under the MIT License - see the LICENSE file for details.