FRON-12153 Add url-based cache eviction and cache TTL (maxAge option)#76
Open
polinazolotukhina wants to merge 4 commits into
Open
FRON-12153 Add url-based cache eviction and cache TTL (maxAge option)#76polinazolotukhina wants to merge 4 commits into
polinazolotukhina wants to merge 4 commits into
Conversation
Adds a `maxAge` option to `ApiRequestOptions` that treats cached entries older than the given milliseconds as a cache miss, triggering a fresh fetch. Expired entries are evicted from the cache on read to prevent memory leaks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Threads the maxAge option through to api.request so the hook respects cache TTL the same way direct api.request calls do. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
deleteCachedResponse(params) required reconstructing the exact request params to compute the cache key, which is impossible for cache keys that embed a serialized request body via extraKey. deleteCachedResponsesByUrl matches entries by url prefix instead, evicting whole request families (sub-paths and query variants) while stopping at path boundaries.
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
deleteCachedResponsesByUrl(urlPrefix)method toApi— removes all cached responses whose requesturlmatches the given prefix, so the next request for any of them fetches fresh dataextraKey(e.g.data-servicessnapshot endpoints), which only the original caller can produce/usersmatches/users,/users/1, and/users?page=2, but not/users-archivemaxAgeoption toApiRequestOptionsandUseApiQueryOptions— cached entries older than the specified milliseconds are treated as a cache miss, triggering a fresh fetchparseApiRequestIdUrlhelper inlib, co-located withapiRequestIdso both directions of the cache-key format live in one modulereadCachedResponsedocs: returnsnullon cache miss, notundefinedUsage
Test plan
deleteCachedResponsesByUrlremoves all entries matching the url prefix — next requests go to network/users/1) and query variants (/users?page=2) of the prefix/users-archive)parseApiRequestIdUrlround-trips the url fromapiRequestIdmaxAge— no network request firedmaxAgeexpires — network request fires and cache is refreshedmaxAgespecified — existing cache behaviour unchanged