Skip to main content

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

  1. Tries to connect to Redis (localhost:6379 by default).
  2. If Redis is not available or fails, it falls back to local disk storage using diskcache.
  3. 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.

Metadata

Release files for FailoverCache 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for FailoverCache 1.0.0
File Size Uploaded Provenance Actions
failovercache-1.0.0.tar.gz 3.7 kB With provenance Details for failovercache-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for FailoverCache 1.0.0
File Interpreter ABI Platform Actions
failovercache-1.0.0-py3-none-any.whl Python 3 none any Details for failovercache-1.0.0-py3-none-any.whl

Total release size: 8.3 kB

Release files / failovercache-1.0.0.tar.gz

Download URL failovercache-1.0.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a0245cbbc384e941651b71182af1c022318e3b77f20d14a1baef044af2db2cc7
BLAKE2b-256 checksum
How to use checksums
2f17644585f99e504106412bf6eaaea7069613d47149c675be1cdc916bb96199
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 20, 2025.

Transparency log

Release files / failovercache-1.0.0-py3-none-any.whl

Download URL failovercache-1.0.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad0ef0b4fa0aeab48c971da54236067d3c0553a828e5dca58c279b67544d838c
BLAKE2b-256 checksum
How to use checksums
b8b42383d8d7c3009fb83851345ed20a4b8dd6594282548e6df243d44e450568
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 20, 2025.

Transparency log

Security for FailoverCache 1.0.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for failovercache-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 20, 2025.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page