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
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 cachemaster-0.0.2.tar.gz.
File metadata
- Download URL: cachemaster-0.0.2.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 |
9a4cf9b9e2bb32cbfe2ee3cf807e2f62310d5f3556cc942110642e31d5271882
|
|
| MD5 |
d505bbf089d303756d44ca2f94c215f1
|
|
| BLAKE2b-256 |
9e3398fff539ac8454810c0c9c420aafb8023a6c14384e9e45a786e53d40af27
|
File details
Details for the file cachemaster-0.0.2-py3-none-any.whl.
File metadata
- Download URL: cachemaster-0.0.2-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
383083bb944141f07f90a928110009d835ed37db5d478f28f41c6f337a9483e9
|
|
| MD5 |
587cfbf26b2ea702f474942b1375d3ab
|
|
| BLAKE2b-256 |
4065c08c52f4a793d002cd24b335b434949db489d893d07907b02ce629c365fc
|