Skip to main content

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

  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.

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

failovercache-0.0.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

failovercache-0.0.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file failovercache-0.0.2.tar.gz.

File metadata

  • Download URL: failovercache-0.0.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for failovercache-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c01e2f646e243ea680948a75b9e77ed3032969bcc093414bfa246510e11fe960
MD5 952bdacee9388639636670a359df659a
BLAKE2b-256 cfb931b0a2aab7e454587233e0c01ff5c6c50991dab7a2601b7a763976415a99

See more details on using hashes here.

Provenance

The following attestation bundles were made for failovercache-0.0.2.tar.gz:

Publisher: python-publish.yml on Endkind/FailoverCache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file failovercache-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: failovercache-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for failovercache-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d71c27c362145caae4eed0cb92884dd6c44600e22bf236d8ec4e93ac8e39008b
MD5 5d46c30f5deaa90ed09d013f684ad1a8
BLAKE2b-256 c70b0fb167b799728c96bec4ae462a1d4cfc16a0cb1ef0919439c5dddeb97352

See more details on using hashes here.

Provenance

The following attestation bundles were made for failovercache-0.0.2-py3-none-any.whl:

Publisher: python-publish.yml on Endkind/FailoverCache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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