Skip to content

Add an optional cacheTTL to ReportOptions arguments #13629

Closed

Description

@tofumatt

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's fetchOptions options accept an optional cacheTTL, in seconds.
    • cacheTTL will not need any special handling since it won't be part of the first argument to getReport (eg. the options argument).
  • When a report is requested with a cacheTTL, that value is passed through to googlesitekit/api's get() and governs how long the response is considered fresh.
  • Reports requested without a cacheTTL keep the existing one-hour behaviour, and their cache keys are byte-for-byte unchanged.
  • Two callers requesting the same report with different cacheTTL values still share one in-flight request and one stored report.
  • No user-visible change.

Implementation Brief

  • Add cacheTTL argument to fetchOptions in getReport. Make fetchOptions an explicit type and add cacheTTL to it (cacheTTL?: number).
  • Ensure separateFetchOptionsFromArgs also detects cacheTTL as an argument key in the second object, same as 'signal' is handled. (see:
    */
    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 createFetchStore controlCallback's to pass cacheTTL through to the control callback along with signal. (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.js to assert a report requested with cacheTTL passes it to get() (spy on googlesitekit-api), that one without it does not, and that two selectors differing only in cacheTTL produce a single fetch.
  • Update assets/js/modules/search-console/datastore/report.test.js/assets/js/modules/analytics-4/datastore/report.test.js with the equivalent assertions, as they will rely on cacheTTL.

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

  1. self-assigned this
    on Sep 18, 2026
  2. removed their assignment
    on Sep 18, 2026
  3. eugene-manuilov commented on Sep 21, 2026

    @eugene-manuilov
    Collaborator
    • Analytics 4 and Search Console report options accept an optional cacheTTL, in seconds.

    @tofumatt, why report options? We already have fetchOptions as the third argument in the getReport selector that allows us pass a signal instance. We should add cacheTTL to that fetchOptions param and bypass it to the fetch store in the same way as we do it for signal. No need to mess with report options at all.

    getReport( state, options, fetchOptions ) {

  4. tofumatt commented on Sep 22, 2026

    @tofumatt
    CollaboratorAuthor

    Oh, good point, I've made those changes and I think it simplifies things 👍🏻

  5. eugene-manuilov commented on Sep 23, 2026

    @eugene-manuilov
    Collaborator

    Thanks, IB ✔️

  6. removed their assignment
    on Sep 23, 2026
  7. removed their assignment
    on Oct 1, 2026
  8. self-assigned this
    on Oct 5, 2026
  9. mohitwp commented on Oct 6, 2026

    @mohitwp
    Collaborator

    QA Update ✅

    Tested on a site with Search Console and Analytics connected.

    • Verified Search Console report/widgets load successfully.
    • Verified Analytics report/widgets load successfully.
    • Confirmed reports continue to load as expected with no user-visible regressions.
    • Also connected AdSense and verified the related dashboard widgets load correctly.
    • Verified PDF report download works successfully.
    • No unexpected errors or regressions observed during testing.
  10. removed their assignment
    on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0High priorityTeam SIssues for Squad 1Type: EnhancementImprovement of an existing feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions