--- id: python-redis-cache version: "4.0.2" license: MIT license_treatment: permissive maintenance: aging --- # python-redis-cache — Basic Redis caching for functions License: permissive · Maintenance: aging · Downloads: 200.8K/mo ## What it is and what it does python-redis-cache wraps Python functions with a decorator that automatically caches their return values in Redis, keyed by function identity and arguments. When a decorated function is called with the same arguments again, the cached result is returned instead of re-executing the function body. It handles serialization of arguments and results (JSON by default), supports time-to-live (TTL) expiration, per-function namespaces, and Redis cluster mode via hash-tag key prefixes. The package is designed for simple, declarative caching of expensive computations—database queries, API calls, heavy calculations—without modifying function logic. It provides methods to invalidate individual cached entries or clear all cached values for a function, and an optional exception handler to gracefully fall back to the original function if Redis is unavailable. The main constraint is that arguments and return values must be serializable; instance methods require refactoring to static methods or custom serializers to avoid serializing `self`. Use it for: - Cache expensive database queries or API responses to reduce latency on repeated calls with identical parameters. - Memoize computationally intensive calculations across multiple function invocations to improve performance. - Reduce load on external services by caching their responses with a configurable TTL before re-fetching. - Implement a shared cache layer for multiple Python processes or services using a centralized Redis instance. - Speed up test suites by caching slow fixture setup or mock data generation across test runs. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Decorator-based caching for Python functions using Redis as the backend store, with support for TTL, cache invalidation, and Redis cluster compatibility. Yes, if you have Redis available and need straightforward function-level caching. The decorator pattern is intuitive and the package is stable with no known vulnerabilities. However, maintenance is aging (507 days since last release); consider it for established, low-change codebases rather than projects requiring active upstream support. Verify Python 3.6 compatibility claims if you target that version. ## Install pip install python-redis-cache uv add python-redis-cache poetry add python-redis-cache ## Installing python-redis-cache Before you install: Low friction install with a single runtime dependency on redis. Maintenance status is aging—last release was 507 days ago, though the repository remains active and not archived. License in practice: MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute this package freely provided you include the license notice. Quickstart: pip install python-redis-cache from redis import StrictRedis client = StrictRedis(host="redis", decode_responses=True) # Create cache instance and decorate function @cache.cache() def my_func(arg1, arg2): return expensive_operation() my_func(1, 2) # Cached on second call my_func.invalidate(1, 2) # Clear specific entry my_func.invalidate_all() # Clear all entries Requires Redis 5+ running and accessible; arguments and return values must be JSON-serializable by default (or use a custom serializer). Verify before relying: - Whether Python 3.6 compatibility claim ('should work in Python 3.6+, but not tested') reflects actual tested support. - Current stability and adoption rate given 507 days since last release and aging maintenance status. - Performance characteristics and overhead of the decorator pattern in production workloads. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: aging - Downloads: 200.8K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags redis function caching decorator, cache python functions with redis, function result caching redis, redis cache decorator, memoization with redis, function memoization redis, redis ttl cache, caching, redis, memoization [View on SkillFed](https://skillfed.io/packages/python-redis-cache) · [View on PyPI](https://pypi.org/project/python-redis-cache/)