Skip to content

Commit dbb445f

Browse files
authored
Merge pull request #4 from Hamdal/feat/cache-and-refresh-policy
Feat/cache and refresh policy
2 parents 5c900bc + ab59fc0 commit dbb445f

3 files changed

Lines changed: 1001 additions & 331 deletions

File tree

packages/syncache/lib/src/policy.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,18 @@ enum Policy {
5555
/// 3. If no cache exists and online, fetch and return
5656
/// 4. If no cache and offline, throw [CacheMissException]
5757
staleWhileRefresh,
58+
59+
/// Returns cached data if available; always refreshes in background.
60+
///
61+
/// Similar to [staleWhileRefresh] but triggers a background refresh even
62+
/// if the cache is still valid. This ensures that subscribers always
63+
/// receive the most up-to-date data while still benefiting from fast
64+
/// cache access.
65+
///
66+
/// Behavior:
67+
/// 1. If cache exists, return it immediately
68+
/// 2. Always trigger background refresh if online
69+
/// 3. If no cache exists and online, fetch and return
70+
/// 4. If no cache and offline, throw [CacheMissException]
71+
cacheAndRefresh
5872
}

0 commit comments

Comments
 (0)