Skip to content

dataconnect(change): Change CACHE_ONLY behavior to return stale data instead of throwing#7885

Merged
dconeybe merged 3 commits intomainfrom
dconeybe/dataconnect/FetchPolicy3
Mar 9, 2026
Merged

dataconnect(change): Change CACHE_ONLY behavior to return stale data instead of throwing#7885
dconeybe merged 3 commits intomainfrom
dconeybe/dataconnect/FetchPolicy3

Conversation

@dconeybe
Copy link
Copy Markdown
Contributor

@dconeybe dconeybe commented Mar 9, 2026

This PR modifies dataconnect's offline caching behavior for queries using the CACHE_ONLY fetch policy in the firebase-dataconnect module. Previously, requesting data with CACHE_ONLY would throw an exception if the cached data was older than the configured maxAge. With this change, CACHE_ONLY will return the stale data instead of throwing. An exception is now only thrown when the data is entirely absent from the cache.

Highlights

  • CACHE_ONLY Behavior Change: Queries executed with the CACHE_ONLY fetch policy will now return stale cached data instead of throwing an exception if the data has expired according to maxAge.
  • Cache Lookup Flexibility: Updated the internal DataConnectCacheDatabase.getQueryResult() to accept a staleResult parameter, allowing the caller to specify whether stale data should be surfaced as Found, Stale, or NotFound.
  • Extensive Test Coverage: Added comprehensive integration and unit tests verifying the behavior of various fetch policies (CACHE_ONLY, PREFER_CACHE, default) against different maxAge configurations (passed, not passed, zero, infinite).
Changelog
  • CHANGELOG.md
    • Added PR number.
  • QueryCachingIntegrationTest.kt
    • Added integration tests for various fetch policies and maxAge combinations.
  • CachingConnector.kt
    • Made fetchPolicy parameter optional in getString.
  • DataConnectGrpcRPCs.kt
    • Refactored cache lookup to pass the expected staleResult based on the fetch policy.
  • DataConnectCacheDatabase.kt
    • Added staleResult parameter to getQueryResult() to control stale data handling.
  • DataConnectCacheDatabaseUnitTest.kt
    • Added unit tests to verify getQueryResult() with the new staleResult parameter.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@dconeybe
Copy link
Copy Markdown
Contributor Author

dconeybe commented Mar 9, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the behavior of the CACHE_ONLY fetch policy to return stale data instead of throwing an exception, which is a significant and useful change. The implementation involves refactoring the caching logic into a new executeQueryAgainstCache function in DataConnectGrpcRPCs and enhancing getQueryResult in DataConnectCacheDatabase to handle stale data more flexibly. The changes are accompanied by a comprehensive set of new integration and unit tests that cover the new behavior thoroughly. The code quality is high, with good use of helper functions in tests to reduce duplication. I have one minor suggestion to enhance test coverage in a property-based test.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 9, 2026

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

@dconeybe dconeybe marked this pull request as ready for review March 9, 2026 20:23
@dconeybe dconeybe merged commit 0bb2eec into main Mar 9, 2026
43 checks passed
@dconeybe dconeybe deleted the dconeybe/dataconnect/FetchPolicy3 branch March 9, 2026 21:29
@github-actions github-actions Bot mentioned this pull request Mar 10, 2026
@firebase firebase locked and limited conversation to collaborators Apr 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants