Skip to content

Feat/cache and refresh policy#4

Merged
Hamdal merged 4 commits intomainfrom
feat/cache-and-refresh-policy
Mar 18, 2026
Merged

Feat/cache and refresh policy#4
Hamdal merged 4 commits intomainfrom
feat/cache-and-refresh-policy

Conversation

@Hamdal
Copy link
Copy Markdown
Owner

@Hamdal Hamdal commented Mar 18, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new caching policy (Policy.cacheAndRefresh) and refactors Syncache policy execution into a shared internal executor/strategy setup, along with a comprehensive test suite for the new policy.

Changes:

  • Introduces Policy.cacheAndRefresh (always returns cache immediately if present and refreshes in background when online).
  • Refactors Syncache.get, getWithMeta, and getConditional to use a unified _executePolicy + _FetchStrategy abstraction.
  • Adds tests covering cache hits, stale hits, offline behavior, background refresh, deduplication, and observer notifications for cacheAndRefresh.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/syncache/lib/src/policy.dart Adds the cacheAndRefresh policy and documents expected behavior.
packages/syncache/lib/src/syncache.dart Refactors policy logic into _executePolicy/strategies and implements cacheAndRefresh via shared SWR logic.
packages/syncache/test/cache_and_refresh_test.dart New test coverage for Policy.cacheAndRefresh behavior (get/getWithMeta/watch/observers/dedup).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@Hamdal Hamdal force-pushed the feat/cache-and-refresh-policy branch from 108e553 to fb78dda Compare March 18, 2026 14:10
@Hamdal Hamdal requested a review from Copilot March 18, 2026 14:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new caching policy (Policy.cacheAndRefresh) to Syncache to always return cached data immediately (if present) while triggering an online background refresh, and refactors policy execution into a unified strategy-based implementation.

Changes:

  • Introduces Policy.cacheAndRefresh in the policy enum with documented behavior.
  • Refactors Syncache.get, getWithMeta, and conditional-get paths to use a shared _executePolicy + _FetchStrategy abstraction.
  • Adds a comprehensive test suite covering cacheAndRefresh behavior (get/getWithMeta/watch/dedup/observer comparisons).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/syncache/lib/src/policy.dart Adds the new cacheAndRefresh policy and its documentation.
packages/syncache/lib/src/syncache.dart Refactors policy handling into unified execution paths and adds shared stale-while-refresh/cache-and-refresh logic.
packages/syncache/test/cache_and_refresh_test.dart Adds tests validating cacheAndRefresh behavior and observer/dedup semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@Hamdal Hamdal force-pushed the feat/cache-and-refresh-policy branch from fb78dda to ab59fc0 Compare March 18, 2026 14:22
@Hamdal Hamdal requested a review from Copilot March 18, 2026 14:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new caching policy (Policy.cacheAndRefresh) to the Syncache package, enabling “return cache immediately, but always refresh in the background when online” behavior. This fits into Syncache’s existing policy-driven fetch pipeline and reactive watcher model.

Changes:

  • Introduces Policy.cacheAndRefresh with documented behavior in policy.dart.
  • Refactors Syncache.get/getWithMeta/getConditional policy handling into a shared _executePolicy + strategy pattern and factors out shared SWR/CAR logic.
  • Adds comprehensive tests covering cacheAndRefresh behavior across get, getWithMeta, watch, deduplication, and observer notifications.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/syncache/lib/src/policy.dart Adds the new cacheAndRefresh enum value and documents semantics.
packages/syncache/lib/src/syncache.dart Refactors policy execution into _executePolicy / _executeStaleWhileRefresh and adds strategy types; wires in cacheAndRefresh.
packages/syncache/test/cache_and_refresh_test.dart New test suite validating cacheAndRefresh behavior (including offline, dedup, observers, watch).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

.then((_) {
_notify(key, isFromCache: false);
}).catchError((Object e, StackTrace st) {
_notifyObservers((o) => o.onFetchError(key, e, st));
Comment on lines +1404 to +1407
/// When [skipNotify] is true, the method will not call [_notify] after
/// cache hits or fetches. This is used by [getWithMeta] since the meta
/// strategy handles value notifications internally via [_notifyValue],
/// and [watchWithMeta] handles meta notifications via manual emission.
@Hamdal Hamdal merged commit dbb445f into main Mar 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants