A flexible Python cache system with automatic fallback to disk when Redis is unavailable
Project description
FailoverCache
FailoverCache is a flexible and persistent Python caching library that automatically falls back to disk storage when Redis is unavailable. Ideal for development and production environments where Redis may not always be present.
🚀 Features
- 🔁 Automatic fallback from Redis to diskcache
- ⏳ Time-To-Live (TTL) support for all values
- 🧠
remember()helper to avoid duplicate calculations - 🧹 Flush the entire cache
- 🔄 Extend or set TTL after creation
- ✅ No Redis required during development
📦 Installation
pip install FailoverCache
🧪 Example Usage
from FailoverCache import FailoverCache
cache = FailoverCache()
# Store a value for 60 seconds
cache.put("greeting", "hello world", ttl=60)
# Retrieve it later
print(cache.get("greeting")) # hello world
# Only compute if not cached
data = cache.remember("expensive", lambda: "result_of_heavy_work", ttl=300)
# Extend TTL by 120 seconds
cache.extend_ttl("greeting", 120)
# Set TTL to exactly 300 seconds
cache.set_ttl("greeting", 300)
# Flush all cache entries
cache.flush()
📂 How it works
- Tries to connect to Redis (
localhost:6379by default). - If Redis is not available or fails, it falls back to local disk storage using
diskcache. - All operations transparently use the first working backend.
🔧 Configuration
You can customize Redis host/port and disk cache path:
cache = FailoverCache(redis_host="redis", redis_port=6379, diskcache_directory=".my_cache")
📄 License
FailoverCache is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file failovercache-1.0.0.tar.gz.
File metadata
- Download URL: failovercache-1.0.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0245cbbc384e941651b71182af1c022318e3b77f20d14a1baef044af2db2cc7
|
|
| MD5 |
f267f039233c7758c220b6a477810b3d
|
|
| BLAKE2b-256 |
2f17644585f99e504106412bf6eaaea7069613d47149c675be1cdc916bb96199
|
Provenance
The following attestation bundles were made for failovercache-1.0.0.tar.gz:
Publisher:
python-publish.yml on Endkind/FailoverCache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
failovercache-1.0.0.tar.gz -
Subject digest:
a0245cbbc384e941651b71182af1c022318e3b77f20d14a1baef044af2db2cc7 - Sigstore transparency entry: 245323696
- Sigstore integration time:
-
Permalink:
Endkind/FailoverCache@75c7c2c271803361141fd05d03da083651479af4 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Endkind
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@75c7c2c271803361141fd05d03da083651479af4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file failovercache-1.0.0-py3-none-any.whl.
File metadata
- Download URL: failovercache-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad0ef0b4fa0aeab48c971da54236067d3c0553a828e5dca58c279b67544d838c
|
|
| MD5 |
adfc27a58cac3f1979721a562a7801c5
|
|
| BLAKE2b-256 |
b8b42383d8d7c3009fb83851345ed20a4b8dd6594282548e6df243d44e450568
|
Provenance
The following attestation bundles were made for failovercache-1.0.0-py3-none-any.whl:
Publisher:
python-publish.yml on Endkind/FailoverCache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
failovercache-1.0.0-py3-none-any.whl -
Subject digest:
ad0ef0b4fa0aeab48c971da54236067d3c0553a828e5dca58c279b67544d838c - Sigstore transparency entry: 245323706
- Sigstore integration time:
-
Permalink:
Endkind/FailoverCache@75c7c2c271803361141fd05d03da083651479af4 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Endkind
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@75c7c2c271803361141fd05d03da083651479af4 -
Trigger Event:
release
-
Statement type: