Skip to main content

A flexible caching system with in-memory and Redis support

Project description

๐Ÿš€ CacheMaster - High-Performance Caching Library

Python MIT License

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 caching
  • pytest>=7.0.0 โ€“ For testing
  • pytest-mock>=3.10 โ€“ Mocks for testing
  • setuptools>=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.2.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cachemaster-0.0.2-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

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

Hashes for cachemaster-0.0.2.tar.gz
Algorithm Hash digest
SHA256 9a4cf9b9e2bb32cbfe2ee3cf807e2f62310d5f3556cc942110642e31d5271882
MD5 d505bbf089d303756d44ca2f94c215f1
BLAKE2b-256 9e3398fff539ac8454810c0c9c420aafb8023a6c14384e9e45a786e53d40af27

See more details on using hashes here.

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

Hashes for cachemaster-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 383083bb944141f07f90a928110009d835ed37db5d478f28f41c6f337a9483e9
MD5 587cfbf26b2ea702f474942b1375d3ab
BLAKE2b-256 4065c08c52f4a793d002cd24b335b434949db489d893d07907b02ce629c365fc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page