Caching providers for Toggly feature flag management (Redis, Memcached)
Project description
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:
- It first tries to load from the snapshot provider (cache)
- If not found, it fetches from the Toggly API
- 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.0redis>=4.0.0(for Redis provider)pymemcache>=4.0.0(for Memcached provider)
License
MIT License - see LICENSE for details.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file toggly_cache-0.1.0.tar.gz.
File metadata
- Download URL: toggly_cache-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36633f1bb329b80040dbebcb2df27327241f54b4ee3698dc952bf3809dabce8f
|
|
| MD5 |
d96f22803506e97e1bf8b9fd4d1c7581
|
|
| BLAKE2b-256 |
7d8f362b13b8aa3e48f15605f52d68e91b70565e9d6993cff35e0bd49ecf071f
|
Provenance
The following attestation bundles were made for toggly_cache-0.1.0.tar.gz:
Publisher:
sdk-python-release.yml on ops-ai/Toggly.FeatureManagement
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
toggly_cache-0.1.0.tar.gz -
Subject digest:
36633f1bb329b80040dbebcb2df27327241f54b4ee3698dc952bf3809dabce8f - Sigstore transparency entry: 1015529906
- Sigstore integration time:
-
Permalink:
ops-ai/Toggly.FeatureManagement@485f914a4b69c7145471e2e979d43921f0908c95 -
Branch / Tag:
refs/heads/develop - Owner: https://github.com/ops-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-python-release.yml@485f914a4b69c7145471e2e979d43921f0908c95 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file toggly_cache-0.1.0-py3-none-any.whl.
File metadata
- Download URL: toggly_cache-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
519dabc215ae495b30fcedc3a099dd32b670b1a54523f18f336316eefd5f961d
|
|
| MD5 |
906c25fd194245210368ae3dfc935fb0
|
|
| BLAKE2b-256 |
d90f5623c6276a33f311717d92e9275e3428749798a3440b354856366af7bdce
|
Provenance
The following attestation bundles were made for toggly_cache-0.1.0-py3-none-any.whl:
Publisher:
sdk-python-release.yml on ops-ai/Toggly.FeatureManagement
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
toggly_cache-0.1.0-py3-none-any.whl -
Subject digest:
519dabc215ae495b30fcedc3a099dd32b670b1a54523f18f336316eefd5f961d - Sigstore transparency entry: 1015530006
- Sigstore integration time:
-
Permalink:
ops-ai/Toggly.FeatureManagement@485f914a4b69c7145471e2e979d43921f0908c95 -
Branch / Tag:
refs/heads/develop - Owner: https://github.com/ops-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-python-release.yml@485f914a4b69c7145471e2e979d43921f0908c95 -
Trigger Event:
workflow_dispatch
-
Statement type: