A flexible caching system with in-memory and Redis support
Project description
๐ CacheMaster - High-Performance Caching Library
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.
โจ Features
- โ 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
๐ Project Structure
CacheMaster/
โโโ src/
โ โโโ cache/
โ โ โโโ __init__.py
โ โ โโโ base_cache.py
โ โ โโโ core_cache.py
โ โ โโโ mem_cache.py
โ โ โโโ redis_cache.py
โ โโโ config/
โ โ โโโ __init__.py
โ โ โโโ cache_config.py
โโโ tests/
โโโ pyproject.toml
โโโ setup.cfg
โโโ setup.py
โโโ README.md
โโโ LICENSE
โโโ .gitignore
๐ฆ Installation
CacheMaster requires Python 3.7+ and the following dependencies:
๐ง Dependencies:
redis>=4.5.0โ Required for Redis-based cachingpytest>=7.0.0โ For testingpytest-mock>=3.10โ Mocks for testingsetuptools>=65.0.0,wheel>=0.40.0โ For packaging
๐ฅ Install via pip
pip install CacheMaster
๐ Running the Cache Application
To 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")
๐ฅ Usage
Basic Cache Operations
# 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
Function Caching with Decorators
@redis_cache.decorator_cache(namespace="users", timeout=300, keys=["user_id"])
def get_user_data(user_id):
return expensive_database_call(user_id)
Batch Operations
# 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"])
Incrementing & Decrementing
local_cache.set("counter", 10)
local_cache.incr("counter", 2) # 12
local_cache.decr("counter", 1) # 11
๐ Running Tests
To ensure everything works correctly, install the development dependencies and run:
pip install -e .[dev]
pytest tests/
If using requirements.txt:
pip install -r requirements.txt
pytest tests/
To ensure everything works correctly, run:
pytest tests/
๐ฏ How CacheMaster Helps You
- ๐ 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.
๐ License
MIT License
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
cachemaster-0.0.3.tar.gz
(11.2 kB
view details)
File details
Details for the file cachemaster-0.0.3.tar.gz.
File metadata
- Download URL: cachemaster-0.0.3.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcf1d317c222a1eee280b9db01935895a4eb30106b65d01bc79d9d2073233d5b
|
|
| MD5 |
e4490ff4d28a82696d6c1a9f7f205df3
|
|
| BLAKE2b-256 |
e682e48310cf127e8eed0a1e8045e914fdaeecab5d07a3ad80ba53e1ddcd6fc8
|