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.1.0.tar.gz (12.6 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.1.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cachemaster-0.1.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.17 Linux/6.8.0-1021-azure

File hashes

Hashes for cachemaster-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3111f64926405b10697fb3691c37d1ec000b83e0799c3985bfdd9357f5e2d697
MD5 5454218459c6c0012b1f79cbc1addb97
BLAKE2b-256 ba59f99b47c38904465d1e0a9da8a4e4f4f9555b9b8f580077240fa9f8f15d43

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cachemaster-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.17 Linux/6.8.0-1021-azure

File hashes

Hashes for cachemaster-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9389a0950ef03b0e8d3fd92d4453075b3eca5f01244951f616b90405fc215e0
MD5 746181014b9a0e8b4231c68e7bf7975f
BLAKE2b-256 4b097ae8bc3a979e23fe62bd29aac70ddd44e4e79671098373ebe7a7282249b2

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