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-1.0.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

failovercache-1.0.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

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

Hashes for failovercache-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a0245cbbc384e941651b71182af1c022318e3b77f20d14a1baef044af2db2cc7
MD5 f267f039233c7758c220b6a477810b3d
BLAKE2b-256 2f17644585f99e504106412bf6eaaea7069613d47149c675be1cdc916bb96199

See more details on using hashes here.

Provenance

The following attestation bundles were made for failovercache-1.0.0.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-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

Hashes for failovercache-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad0ef0b4fa0aeab48c971da54236067d3c0553a828e5dca58c279b67544d838c
MD5 adfc27a58cac3f1979721a562a7801c5
BLAKE2b-256 b8b42383d8d7c3009fb83851345ed20a4b8dd6594282548e6df243d44e450568

See more details on using hashes here.

Provenance

The following attestation bundles were made for failovercache-1.0.0-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