You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: implement cache management methods and enhance ExecuteCachedAsync functionality
- Added InvalidateCache, InvalidateCacheByPrefix, and ClearCache methods for better cache control.
- Updated ExecuteCachedAsync to ensure only the first caller's callbacks are executed, improving deduplication.
- Enhanced documentation to clarify cache invalidation strategies and callback behaviors.
- Updated version to 2.0.5 and revised release notes to reflect new features and improvements.
| Single component, no deduplication needed |`ExecuteAsync`|
418
418
| Need data without state updates |`LazyLoad`|
419
419
420
+
#### Cache Invalidation
421
+
422
+
Control cached entries when data changes:
423
+
424
+
```csharp
425
+
// Remove specific cached entry
426
+
executor.InvalidateCache($"product-{productId}");
427
+
428
+
// Remove all entries with prefix (e.g., after bulk operation)
429
+
executor.InvalidateCacheByPrefix("product-");
430
+
431
+
// Clear all cached results (e.g., on user logout)
432
+
executor.ClearCache();
433
+
```
434
+
435
+
> **Note:** Only the first caller's callbacks (loading, success, error) are executed. Concurrent callers receive the same result but their callbacks are NOT invoked. This is intentional for deduplication.
<p>Service interface for executing async actions with automatic loading, success, and error state management. Provides caching and deduplication capabilities for optimized data fetching.</p>
<p>Executes an async action with full deduplication of both fetch and state updates. When multiple components call this with the same key, only 2 state updates occur instead of N×2.</p>
loading: s => s with { Product = s.Product.ToLoading() },
912
+
success: (s, p) => s with { Product = AsyncData.Success(p) },
913
+
error: (s, ex) => s with { Product = AsyncData.Failure(ex.Message) },
914
+
cacheFor: TimeSpan.FromMinutes(5)
915
+
);</code></pre>
916
+
</div>
917
+
<p><strong>Important:</strong> Only the first caller's callbacks (loading, success, error) are executed. Concurrent callers waiting for the same cache key receive the result but their callbacks are NOT invoked.</p>
<divclass="alert-title">Important: First Caller's Callbacks Only</div>
173
+
<p>Only the first caller's <code>loading</code>, <code>success</code>, and <code>error</code> callbacks are executed. Concurrent callers waiting for the same cache key receive the result but their callbacks are NOT invoked. This ensures exactly 2 state updates regardless of concurrent caller count. Ensure all callers use consistent callbacks, or handle state updates separately after receiving the cached result.</p>
0 commit comments