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.

Links

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

toggly_cache-0.1.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

toggly_cache-0.1.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file toggly_cache-0.1.1.tar.gz.

File metadata

  • Download URL: toggly_cache-0.1.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for toggly_cache-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e344071982c6fdedc88396c63136afc61a5ec3bba4dc3920bb9ef38f6166bf79
MD5 f7ba5d8869b88cff1c45d0dc2defd8c8
BLAKE2b-256 cbdf544ec32e81b7d6ff8769ddc3975bbe3860f866fc1ef50d8f7847d213b229

See more details on using hashes here.

Provenance

The following attestation bundles were made for toggly_cache-0.1.1.tar.gz:

Publisher: sdk-python-release.yml on ops-ai/Toggly.FeatureManagement

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

File details

Details for the file toggly_cache-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: toggly_cache-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for toggly_cache-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad361f1d59fdc588d4b25e1b9e6d6e3c063503344e620caefc4f0f5b3a2bf49f
MD5 0c600c8a264469ea4035bfc877734bff
BLAKE2b-256 1970281a7c8b0ce65b465c103433092eeac9c805e7979808539ea915ae83cedd

See more details on using hashes here.

Provenance

The following attestation bundles were made for toggly_cache-0.1.1-py3-none-any.whl:

Publisher: sdk-python-release.yml on ops-ai/Toggly.FeatureManagement

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

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

0.0.1

2 files

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