Skip to content

Comments

feat: Implement AbstractAsyncFeatureCache for async SDK clients#80

Open
vazarkevych wants to merge 8 commits intomainfrom
feature/async-cache
Open

feat: Implement AbstractAsyncFeatureCache for async SDK clients#80
vazarkevych wants to merge 8 commits intomainfrom
feature/async-cache

Conversation

@vazarkevych
Copy link
Collaborator

@vazarkevych vazarkevych commented Dec 2, 2025

This PR introduces asynchronous feature caching support, which is critical for the asynchronous operation mode of the SDK (GrowthBookClient). Utilizing an async cache (e.g., Redis) significantly reduces latency and API load by eliminating the need for HTTP requests during a Cache HIT.

Changes

  • Added AbstractAsyncFeatureCache: Defined the interface for asynchronous caching, including methods like get(key), set(key, value, ttl).
  • Updated FeatureRepository: The load_features_async method now utilizes self.async_cache (if provided in Options) to check and store features in the cache.

# Conflicts:
#	growthbook/growthbook.py
# Conflicts:
#	growthbook/growthbook.py
# Conflicts:
#	growthbook/growthbook.py
class FeatureRepository(object):
def __init__(self) -> None:
self.cache: AbstractFeatureCache = InMemoryFeatureCache()
self.async_cache: Optional[AbstractAsyncFeatureCache] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting an async cache in the sync feature repo implementation isn't ideal. We could rather override the methods in EnhancedFeatureRepository which is used by the async client and leave the super class untouched, so we keep the sync vs async executions isolated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants