python-cache-service
A lightweight, namespaced caching service using Redis.
Supports fast prototyping and production-ready use, with built-in support for Redis and fakeredis for tests.
🚀 Features
- 🔑 Namespaced keys to avoid collisions
- ⏳ Optional TTL for cache expiration
- 🧪
fakeredissupport for seamless unit testing - 🧩 Decorator to cache function results transparently
- 🧼 Cache clearing by namespace
📦 Installation
pip install python-cache-service
Usage
from cache.domain.factories.cache_service_factory import CacheServiceFactory
cache = CacheServiceFactory.create(namespace="my_app")
# Store a value
cache.set("my_key", {"data": 123}, ttl_seconds=3600)
# Retrieve a value
value = cache.get("my_key")
# Delete a value
cache.delete("my_key")
# Clear all keys in the namespace
cache.clear()
Configuration
You can configure the cache service by setting environment variables:
- REDIS_HOST=localhost
- REDIS_PORT=6379
- REDIS_DB=0
🧪 Using in tests
from cache.domain.factories.cache_service_factory import CacheServiceFactory
cache = CacheServiceFactory.createTest()
cache.set("test_key", [1, 2, 3])
assert cache.get("test_key") == [1, 2, 3]
You can also disable caching entirely in test mode:
from cache.domain.factories.cache_service_factory import CacheServiceFactory
cache = CacheServiceFactory.createTest(disabled=True)
🎯 Using the @cache_result decorator
from cache.decorators.cache_result import cache_result
from cache.domain.factories.cache_service_factory import CacheServiceFactory
cache = CacheServiceFactory.create(namespace="my_app")
@cache_result(cache, ttl_seconds=120, key_prefix="my_func", verbose=True)
def heavy_computation(x, y):
return x + y
# First call: computed and cached
heavy_computation(2, 3)
# Second call: cache hit
heavy_computation(2, 3)
🧾 License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for python-cache-service 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_cache_service-0.1.1.tar.gz | 6.1 kB | Without provenance | Details for python_cache_service-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_cache_service-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for python_cache_service-0.1.1-py3-none-any.whl |
Total release size: 12.9 kB
Release files / python_cache_service-0.1.1.tar.gz
| Download URL | python_cache_service-0.1.1.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8639b67632f44b1c19b8271be6811f8a8dd8b5349bbd84353c95a472df46ab6
|
|
BLAKE2b-256 checksum How to use checksums |
49499299d87a3e280c12b1e58d463eb77104f3db94f7a2a180521f0070981e22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.9
|
Release files / python_cache_service-0.1.1-py3-none-any.whl
| Download URL | python_cache_service-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce30d50db9349e67c6754c1e4bd3699697b42faf79eebfdb3958304508980ee4
|
|
BLAKE2b-256 checksum How to use checksums |
83d5e1f66e633011b29c12d7e86f33d181ceff802529cc3193567821b77251ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.9
|
Security for python-cache-service 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.