Repository navigation
Add an optional cacheTTL to ReportOptions arguments #13629
Description
Feature Description
Add an option to set the cache time-to-live value for getReport calls. Required for Fresh Data requests, since they'll be made every five minutes instead of every hour.
The key detail is that cacheTTL must not become part of the cache key. getCacheableReportOptions() in assets/js/util/report-options.ts already strips reportID before options become a key, for exactly this reason: two callers that differ only in a label should share one request and one cache entry. cacheTTL joins that omit list and is passed to get() instead, so it changes no cache keys and cannot fragment the cache: two selectors asking for the same report with different TTLs still share a request; the lower TTL simply lets that shared entry refresh sooner.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
getReport'sfetchOptionsoptions accept an optionalcacheTTL, in seconds.cacheTTLwill not need any special handling since it won't be part of the first argument togetReport(eg. theoptionsargument).
- When a report is requested with a
cacheTTL, that value is passed through togooglesitekit/api'sget()and governs how long the response is considered fresh. - Reports requested without a
cacheTTLkeep the existing one-hour behaviour, and their cache keys are byte-for-byte unchanged. - Two callers requesting the same report with different
cacheTTLvalues still share one in-flight request and one stored report. - No user-visible change.
Implementation Brief
- Add
cacheTTLargument tofetchOptionsingetReport. MakefetchOptionsan explicit type and addcacheTTLto it (cacheTTL?: number). - Ensure
separateFetchOptionsFromArgsalso detectscacheTTLas an argument key in the second object, same as'signal'is handled. (see:)site-kit-wp/assets/js/googlesitekit/data/create-fetch-store.js
Lines 68 to 77 in 501de04
*/ function separateFetchOptionsFromArgs( args ) { const lastArg = args[ args.length - 1 ]; if ( isPlainObject( lastArg ) && 'signal' in lastArg ) { return { fetchArgs: args.slice( 0, -1 ), fetchOptions: lastArg, }; } - Update all
createFetchStorecontrolCallback's to passcacheTTLthrough to the control callback along withsignal. (It may be better to just pass all args through to allow for future extensibility, but unclear.)
Test Coverage
- Update
assets/js/googlesitekit/data/create-fetch-store.test.jsto assert a report requested withcacheTTLpasses it toget()(spy ongooglesitekit-api), that one without it does not, and that two selectors differing only incacheTTLproduce a single fetch. - Update
assets/js/modules/search-console/datastore/report.test.js/assets/js/modules/analytics-4/datastore/report.test.jswith the equivalent assertions, as they will rely oncacheTTL.
QA Brief
- QA should simply check that on a site with Search Console and Analytics connected, a report still loads.
Changelog entry
- N/A
Activity
eugene-manuilov commentedon Sep 21, 2026
@tofumatt, why report options? We already have
fetchOptionsas the third argument in thegetReportselector that allows us pass asignalinstance. We should addcacheTTLto thatfetchOptionsparam and bypass it to the fetch store in the same way as we do it forsignal. No need to mess with report options at all.site-kit-wp/assets/js/modules/analytics-4/datastore/report.js
Line 175 in d1d3539
tofumatt commentedon Sep 22, 2026
Oh, good point, I've made those changes and I think it simplifies things 👍🏻
eugene-manuilov commentedon Sep 23, 2026
Thanks, IB ✔️
mohitwp commentedon Oct 6, 2026
QA Update ✅
Tested on a site with Search Console and Analytics connected.