A high-performance caching engine for Keywords4CV and beyond
A high-performance, thread-safe, and extensible caching engine originally developed for Keywords4CV, but designed for general use in Python applications.
- Flexible Backends: Supports multiple caching backends:
- In-Memory: Uses
cachetools
for fast, thread-safe in-memory caching (LRU, TTL). - Disk: Uses
diskcache
for persistent, on-disk caching. - Hybrid: Combines in-memory and disk caching for optimal performance.
- Custom: Easily extend with your own backends.
- In-Memory: Uses
- Serialization Options: Supports
pickle
(default) andmsgpack
(optional, for improved performance) for serializing cached objects. - Thread and Process Safety: Uses appropriate locking mechanisms to ensure safe concurrent access from multiple threads and processes.
- Memory Management: Includes a
MemoryManager
to monitor system memory usage and adaptively trim caches to prevent out-of-memory errors. - Extensible Design: Provides specialized cache managers for vectors (with optional GPU acceleration using
torch
) and text processing. - Dynamic Configuration: Uses
pydantic
for easy configuration and runtime updates. - Security: Supports optional encryption of cached data using
cryptography
. - Metrics and Monitoring: Built-in metrics tracking (hits, misses, etc.) for integration with monitoring systems (e.g., Prometheus).
- Circuit Breaker: Includes a circuit breaker to handle failures gracefully when using external resources (e.g., API calls for synonyms).
- Comprehensive Testing: Includes a thorough test suite with unit tests and performance benchmarks.
- Well-Documented: Provides clear API documentation and usage examples.
Using pip:
pip install k4cv-caching-framework