CacheMaster is a high-performance caching library that supports both in-memory and Redis-based caching. It provides a simple, flexible API for efficiently storing, retrieving, and managing cache data.
- ✅ Supports In-Memory & Redis Caching
- 🔒 Thread-safe local caching
- 🛠 Customizable serialization (Pickle & JSON for Redis)
- ⏳ Automatic expiration & TTL management
- ⚡ Batch operations for performance optimization
- 🎯 Decorator support for function caching
CacheMaster/
│── src/
│ ├── cache/
│ │ ├── __init__.py
│ │ ├── base_cache.py
│ │ ├── core_cache.py
│ │ ├── mem_cache.py
│ │ ├── redis_cache.py
│ ├── config/
│ │ ├── __init__.py
│ │ ├── cache_config.py
│── tests/
│── CHANGELOG.md
│── poetry.lock
│── pyproject.toml
│── README.md
│── LICENSE
│── .bumpver.toml
│── .gitignore
CacheMaster requires Python 3.7+ and the following dependencies:
redis>=4.0.0– Required for Redis-based cachingpytest>=7.0.0– For testingpytest-mock>=3.10– Mocks for testingpoetry>=2.1.2– For packaging
pip install CacheMasterOr using Poetry:
poetry add dict2objectsTo start using CacheMaster, initialize a cache instance:
from cachemaster.core_cache import CoreCache, CacheType
# Local (In-Memory) Cache
local_cache = CoreCache(app_name="my_app", cache_type=CacheType.LOCAL_CACHE)
# Redis Cache
redis_cache = CoreCache(app_name="my_app", cache_type=CacheType.REDIS_CACHE, redis_url="redis://localhost")# Set and Get
local_cache.set("user_123", {"name": "John"}, timeout=600)
user = local_cache.get("user_123") # Returns: {"name": "John"}
# Delete
local_cache.delete("user_123")
# Check if key exists
exists = local_cache.has_key("user_123") # Returns: False@redis_cache.decorator_cache(namespace="users", timeout=300, keys=["user_id"])
def get_user_data(user_id):
return expensive_database_call(user_id)# Set multiple values
local_cache.set_many({"key1": "value1", "key2": "value2"}, timeout=300)
# Get multiple values
values = local_cache.get_many(["key1", "key2"]) # Returns: {"key1": "value1", "key2": "value2"}
# Delete multiple values
local_cache.delete_many(["key1", "key2"]) local_cache.set("counter", 10)
local_cache.incr("counter", 2) # 12
local_cache.decr("counter", 1) # 11- Clone the repository:
git clone git@github.com:JanardhanSingh98/CacheMaster.git cd CacheMaster - Install dependencies:
poetry install
- Run tests:
poetry run coverage run --omit="tests*" -m pytest
- 🚀 Boosts performance by reducing redundant database queries.
- 💾 Efficient memory management with TTL-based expiration.
- 🔄 Scalable & flexible with both local and distributed caching.
- 📌 Easy to integrate with existing applications.
This project is licensed under the MIT License. See the LICENSE file for details.