Skip to main content

A flexible Python cache system with automatic fallback to disk when Redis is unavailable

Project description

README.md

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 redis diskcache

🧪 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.1.tar.gz (3.8 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.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: failovercache-0.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for failovercache-0.0.1.tar.gz
Algorithm Hash digest
SHA256 be400552a0d38babd6dc4a47d130a08d0a124d8be11ebb6b3ef25b521ae3ae53
MD5 7f140750342fecff424e93b5238a5fa9
BLAKE2b-256 9cd6389819c39774b7b97dfa36fed3795098fff1a26c0b7e216c94baf9dbc0f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: failovercache-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for failovercache-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29e21d84fd694d9e3f68dfc877a728065e38a1c33d0ca49d44512af80eb86f24
MD5 2ef23b32dd8f759dd542ee0530f1aada
BLAKE2b-256 3902c3b0a4fbd56d839ceca717f7157f55d5c3d1b8435f290409cd9a0ec67d10

See more details on using hashes here.

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