-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Description
The Python SDK documentation at https://docs.growthbook.io/lib/python shows examples using AbstractAsyncFeatureCache for custom async caching, but this class doesn't exist in the latest released version (1.4.7).
Documentation Example
The docs show this example for custom async caching:
from redis.asyncio import Redis
from growthbook import GrowthBookClient, Options, AbstractAsyncFeatureCache
class AsyncRedisFeatureCache(AbstractAsyncFeatureCache):
def __init__(self):
self.redis = Redis(host='localhost', port=6379, decode_responses=True)
self.prefix = "gb:async:"
async def get(self, key: str):
data = await self.redis.get(self.prefix + key)
return None if data is None else json.loads(data)
async def set(self, key: str, value: dict, ttl: int) -> None:
await self.redis.set(
self.prefix + key,
json.dumps(value),
ex=ttl
)
async def close(self):
await self.redis.close()
# Create client with custom cache
client = GrowthBookClient(
Options(
api_host="https://cdn.growthbook.io",
client_key="sdk-abc123",
cache=cache # <-- Options doesn't support 'cache' parameter
)
)Actual Behavior
When attempting to use this code with growthbook==1.4.7:
from growthbook import AbstractAsyncFeatureCache
# ImportError: cannot import name 'AbstractAsyncFeatureCache' from 'growthbook'Additionally, the Options class doesn't have a cache parameter.
Investigation
Checking the installed package:
$ pip show growthbook
Name: growthbook
Version: 1.4.7
$ python -c "import growthbook; print([x for x in dir(growthbook) if 'Async' in x or 'Cache' in x])"
['AbstractFeatureCache', 'CacheEntry', 'FeatureCache', 'InMemoryFeatureCache']
# No AbstractAsyncFeatureCacheThe package only contains:
AbstractFeatureCache(sync, for legacyGrowthBookclass)FeatureCache(internal class used byGrowthBookClient)InMemoryFeatureCache(sync implementation)
Expected Behavior
Either:
- Documentation should be updated to remove references to
AbstractAsyncFeatureCacheand custom async caching for version 1.4.7 - Or the documentation should indicate this is a feature coming in a future version (e.g., "Available in v2.0+")
- Or
AbstractAsyncFeatureCacheshould be added to the library to match the documentation
Workaround
For now, custom caching is only supported for the synchronous client:
from growthbook import AbstractFeatureCache, feature_repo
class RedisFeatureCache(AbstractFeatureCache):
# Sync implementation...
pass
# Configure globally for sync client
feature_repo.set_cache(RedisFeatureCache())Environment
- Python: 3.12
- growthbook: 1.4.7
- OS: macOS/Linux
Additional Context
This issue was discovered while implementing Redis caching for a Django application following the official documentation. The documentation appears to be written for a future or unreleased version of the SDK.
Would appreciate clarification on:
- When will
AbstractAsyncFeatureCachebe available? - Should we expect this in a minor or major version update?
- Can the documentation be tagged with version availability?
Thank you!