launchdarkly / cpp-sdks

C++ Client/Server SDKs
Other
5 stars 3 forks source link

fix: improve caching behavior of database integration #444

Closed cwaldren-ld closed 1 month ago

cwaldren-ld commented 1 month ago

This improves the caching behavior of the Lazy Load data system.

Previously, calling AllFlags or AllSegments updated an "allFlags" or "allSegments" key in the unscoped freshness tracker. That's correct, as those keys act as rate limiters for the "all" queries.

It then upserted each individual item in the unscoped freshness tracker.

This is not optimal, as the unscoped tracker is not referenced when we read individual items. This results in cache misses for individual items, even after they were all refreshed.

This change properly adds the individual items into the scoped tracker. Now, AllFlags or AllSegments should result in "priming" the cache for future individual item fetches.

This does have the behavior of syncing the TTL dates of all items to a single point in time.


Before:

[LaunchDarkly] lazy load via redis (JSON): get allFlags - cache miss
[LaunchDarkly] lazy load via redis (JSON): get allSegments - cache miss
[LaunchDarkly] lazy load via redis (JSON): get test - cache miss
[LaunchDarkly] lazy load via redis (JSON): get my-boolean-flag - cache miss

After:

[LaunchDarkly] lazy load via redis (JSON): get allFlags - cache miss
[LaunchDarkly] lazy load via redis (JSON): get allSegments - cache miss
[LaunchDarkly] lazy load via redis (JSON): get test - cache hit
[LaunchDarkly] lazy load via redis (JSON): get my-boolean-flag - cache hit