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
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.1.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.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file cachemaster-0.0.1.tar.gz.

File metadata

  • Download URL: cachemaster-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b84ee383fc5144a29bb047385308b947b8868491b64e30f324d66a059589fcb4
MD5 5d20e738fef49dbfbe274c42ab94b627
BLAKE2b-256 21c8f6ac6a300a5ae3983428b5bf5df3945becb02e9df90bf38eaba6d3bb6edd

See more details on using hashes here.

File details

Details for the file cachemaster-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cachemaster-0.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e9745fcbc504809c7a7fde82ff983dba43a81ca67e039074339e33fedad3032
MD5 0938e60098e8a2996a651b52e8eb1842
BLAKE2b-256 066b2b60a17c1464261c69d7ab58ba0eac90d465a6a74f99dd7dddc92d3de51a

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