feat: Drop persistent-store cache after FDv2 in-memory store init#384
Open
feat: Drop persistent-store cache after FDv2 in-memory store init#384
Conversation
With FDv2, the in-memory store becomes the source of truth for flag evaluations once it receives its first full payload. The persistent store's CachingStoreWrapper continues to hold a duplicate copy of every flag and segment in its ExpiringCache, even though that cache is never read again. This roughly doubled the in-memory footprint of flag data when a persistent store was configured. Add a disable_cache hook that propagates from Store#set_basis through FeatureStoreClientWrapperV2 (and the RedisFeatureStore facade) to CachingStoreWrapper, where it releases the ExpiringCache reference. The cache is still populated during the bootstrap window before set_basis fires, so :expiration / :capacity options remain functional during that window. YARD docs on the Redis, DynamoDB, and Consul integrations note the new FDv2 behavior. Also closes a latent TOCTOU window in CachingStoreWrapper's read paths by capturing @cache to a local variable before the existing nil-guards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With FDv2, the in-memory store (
InMemoryFeatureStoreV2) becomes the source of truth for flag evaluations once it receives its first full payload. The persistent store'sCachingStoreWrappercontinues to hold a duplicate copy of every flag and segment in itsExpiringCache, even though that cache is never read again post-init -- roughly doubling the in-memory flag footprint when a persistent store is configured.This change adds a
disable_cachehook that propagates fromStore#set_basisthroughFeatureStoreClientWrapperV2(and theRedisFeatureStorefacade) down toCachingStoreWrapper, where it releases theExpiringCachereference. The cache is still populated and useful during the bootstrap window beforeset_basisfires, so:expiration/:capacityoptions remain functional during that window; YARD docs on the Redis, DynamoDB, and Consul integrations note the new FDv2 behavior.While here, this also closes a latent TOCTOU window in
CachingStoreWrapper's read paths by capturing@cacheto a local variable before the existing nil-guards, so a concurrentdisable_cachecannot NPE an in-flight reader.Mirrors the Python implementation from
python-server-sdkPR #426.Note
Medium Risk
Changes cache lifecycle behavior for persistent stores by disabling their local cache after the first full FDv2 payload; mistakes could impact persistent-store performance or initialization sequencing. Includes concurrency-sensitive cache handling and new warning-path logging that should be validated under load.
Overview
With FDv2, the SDK now drops the persistent-store in-memory cache once the in-memory store becomes authoritative (after a full
TRANSFER_FULLpayload), reducing duplicate flag/segment memory usage.This introduces a
disable_cachehook that propagates throughStore#set_basis(best-effort with warning on failure),FeatureStoreClientWrapperV2, and the Redis feature-store facade down toIntegrations::Util::CachingStoreWrapper, which releases/clears its cache and updates read paths to safely capture@cachelocally to avoid races.Updates YARD docs for Redis/DynamoDB/Consul cache options to note the FDv2 bootstrap-only behavior, and adds specs covering forwarding/no-op behavior, idempotency, race-safe bypass after disable, and tolerance of missing/raising
disable_cacheimplementations.Reviewed by Cursor Bugbot for commit 1db3fab. Bugbot is set up for automated code reviews on this repo. Configure here.