feat(hooks): honor Cache-Control lifetime for Bible reads - #371
feat(hooks): honor Cache-Control lifetime for Bible reads#371cameronapak wants to merge 10 commits into
Conversation
YPE-5453. Release notes for the in-memory TanStack lifetime work. Co-authored-by: Cameron Pak <cameronandrewpak@gmail.com>
🦋 Changeset detectedLatest commit: 1049a3a The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Add parseCachePolicy so Bible reads can honor remaining max-age minus Age.
YPE-5453. Native policy trims quotes around the max-age value.
240827a to
dbbe965
Compare
Unwrap `{ data, policy }` envelopes in useApiData and set that query's
staleTime and gcTime from remainingMs so remounts in the same provider
honor Cache-Control without changing the public hook surface.
setQueryDefaults alone left the first fetch on the five-minute gcTime. Remaining lifetime now updates that query instance too.
Anonymous object types on the remount `latest` bindings tripped the anti-slop rule. Use the same named probe contract as useApiData.
ReviewJira ticket: YPE-5453 SummarySimpler: yes. Worst: eight public with-policy Bible methods and an envelope that we guess from fields. Pre-flight: DO NOT SHIP. For AgentsHealthy pin: main e580502 vs HEAD 3fa6083. By Simplifier bot, sent on behalf of Cam. |
useApiData now takes { cacheControl: true } so the fetch is typed as
{ data, policy } instead of guessing an envelope from its fields. Bible
hooks use one readWithPolicy; partners still get body-only getters.
Implements YPE-5453: TanStack Query uses remaining Cache-Control lifetime (
max-ageminusAge) for Bible reads under/v1/bibles/{id}.Closes YPE-5453. Does not close YPE-5262 (RN Expo disk cache).
What changes
Cache-Control/Agethe same way Swift and Kotlin do (7-day fallback, Age 0 when missing,no-cache/no-storeskip reuse on remount).GETstays body-only.ApiClient.getWithPolicyreturns{ data, policy }.BibleClient.readWithPolicy(discriminatedBibleCacheRead). Partners still use the body-only getters. There are no publicget*WithPolicytwins.useApiData(key, fetchFn, { cacheControl: true })sofetchFnis typed to return{ data, policy }. BareTstays default-fresh (versions list, highlights, VOTD). No duck-typing of envelopes.remainingMsis written as that query'sstaleTimeandgcTime(setQueryDefaults+ livequery.setOptions).YouVersionProvider. A mounted chapter may stay on screen after expiry; a remount after expiry fetches again.Review follow-up
Simplifier asked not to ship the eight public with-policy methods or a guessed
{ data, policy }envelope. This revision keepsparseCachePolicy,getWithPolicy, andapplyCacheLifetime, and switches opt-in to the explicitcacheControlflag plus one internal Bible read.Verification
parseCachePolicytable matches Kotlin/Swift cases (quotedmax-age, decimals).getWithPolicy2xx / non-2xx.readWithPolicyreturns version + policy.remainingMsfetches; remount after the default five-minute unused window still hits whenremainingMsis longer; mounted observer keeps data past expiry;refetch()fetches.{ data, policy }payload stays data whencacheControlis omitted.Manual network-panel check needs a live
VITE_YVP_APP_KEY(not in this environment).Out of scope
Disk cache, ETag/304, Expires/Date, sharing one query cache across provider instances or Expo WebViews.
Greptile Summary
The PR completes the previously missing hooks integration, allowing opted-in Bible reads to use the API’s remaining Cache-Control lifetime while preserving body-only core getters.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains; the previously reported mismatch between the changeset and hooks implementation has been resolved.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart LR Hook[Bible hook] --> Read[BibleClient.readWithPolicy] Read --> API[ApiClient.getWithPolicy] API --> Policy[Parse Cache-Control and Age] Policy --> Envelope["{ data, policy }"] Envelope --> Query[useApiData] Query --> Lifetime[Apply staleTime and gcTime] Lifetime --> Cache[Provider-local memory cache]Reviews (3): Last reviewed commit: "refactor: type cache-control opt-in and ..." | Re-trigger Greptile
Context used: