Skip to main content

Toggly Cache

Caching providers for Toggly feature flag management. This package provides Redis and Memcached snapshot providers for distributed caching of feature flag definitions.

Installation

# Install with Redis support
pip install toggly-cache[redis]

# Install with Memcached support
pip install toggly-cache[memcached]

# Install with both
pip install toggly-cache[all]

Quick Start

Redis Provider

from toggly import TogglyClient, TogglyConfig
from toggly_cache import RedisSnapshotProvider

# Create a Redis snapshot provider
provider = RedisSnapshotProvider(
    host="localhost",
    port=6379,
    db=0,
    prefix="toggly:",
    ttl=3600,  # Cache for 1 hour
)

# Use with TogglyClient
config = TogglyConfig(
    app_key="your-app-key",
    environment="production",
    snapshot_provider=provider,
)

client = TogglyClient(config)

Memcached Provider

from toggly import TogglyClient, TogglyConfig
from toggly_cache import MemcachedSnapshotProvider

# Create a Memcached snapshot provider
provider = MemcachedSnapshotProvider(
    servers=[("localhost", 11211)],
    prefix="toggly:",
    ttl=3600,  # Cache for 1 hour
)

# Use with TogglyClient
config = TogglyConfig(
    app_key="your-app-key",
    environment="production",
    snapshot_provider=provider,
)

client = TogglyClient(config)

Configuration

Redis Provider Options

Option Type Default Description
client Redis None Existing Redis client instance
host str "localhost" Redis host
port int 6379 Redis port
db int 0 Redis database number
password str None Redis password
prefix str "toggly:" Key prefix for Redis keys
ttl int None TTL in seconds (None = no expiry)

Memcached Provider Options

Option Type Default Description
client Client None Existing pymemcache client
servers list[tuple] None List of (host, port) tuples
prefix str "toggly:" Key prefix for Memcached keys
ttl int 0 TTL in seconds (0 = no expiry)

Using Existing Clients

You can pass an existing Redis or Memcached client:

# Redis
import redis
redis_client = redis.Redis(host="localhost", port=6379)
provider = RedisSnapshotProvider(client=redis_client)

# Memcached
from pymemcache.client.base import Client
memcached_client = Client(("localhost", 11211))
provider = MemcachedSnapshotProvider(client=memcached_client)

Cluster Support

Redis Cluster

from redis.cluster import RedisCluster
from toggly_cache import RedisSnapshotProvider

cluster = RedisCluster(
    host="cluster-node-1",
    port=6379,
)
provider = RedisSnapshotProvider(client=cluster)

Memcached with Multiple Servers

from toggly_cache import MemcachedSnapshotProvider

# Automatically uses HashClient for consistent hashing
provider = MemcachedSnapshotProvider(
    servers=[
        ("memcached-1", 11211),
        ("memcached-2", 11211),
        ("memcached-3", 11211),
    ],
)

How It Works

Cache providers implement the SnapshotProvider interface from the core toggly package. When the TogglyClient loads feature definitions:

  1. It first tries to load from the snapshot provider (cache)
  2. If not found, it fetches from the Toggly API
  3. After fetching, it saves the definitions to the snapshot provider

This enables:

  • Faster startup: Cached definitions are loaded immediately
  • Offline resilience: App works even if Toggly API is temporarily unavailable
  • Reduced API calls: Definitions are cached between restarts
  • Distributed caching: Multiple app instances share the same cache

Requirements

  • Python 3.8+
  • toggly>=0.1.0
  • redis>=4.0.0 (for Redis provider)
  • pymemcache>=4.0.0 (for Memcached provider)

License

MIT License - see LICENSE for details.

Metadata

Release files for toggly-cache 0.1.2

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

Source distribution (sdist)

Source distribution for toggly-cache 0.1.2
File Size Uploaded Provenance Actions
toggly_cache-0.1.2.tar.gz 11.2 kB With provenance Details for toggly_cache-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for toggly-cache 0.1.2
File Interpreter ABI Platform Actions
toggly_cache-0.1.2-py3-none-any.whl Python 3 none any Details for toggly_cache-0.1.2-py3-none-any.whl

Total release size: 20.4 kB

Release files / toggly_cache-0.1.2.tar.gz

Download URL toggly_cache-0.1.2.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3d814d55d6b84ae1fdd02b3247c508784a83272a850c61271050c96a83934c3f
BLAKE2b-256 checksum
How to use checksums
04e55d0583086ba411802f929617c7830998425190b6acf8bc77c2008b4efeeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 15, 2026.

Transparency log

Release files / toggly_cache-0.1.2-py3-none-any.whl

Download URL toggly_cache-0.1.2-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92581f68b4ae6561cc8569eecc27b18861f40a0f89e54d9407315bab8d870636
BLAKE2b-256 checksum
How to use checksums
d8d89a4ad8ab09fb799b95f89349062437afcc8cee7070a0e6c412ceb9730d73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 15, 2026.

Transparency log

Security for toggly-cache 0.1.2

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 toggly_cache-0.1.2.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 Sep 15, 2026.

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