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
-`forceRefresh` (bool): Bypass cache and fetch fresh data
522
563
-`strategy` (CacheStrategy): Cache strategy to use (default: `CacheStrategy.cacheFirst`)
564
+
-`onError` (void Function(CacheError)?): Callback for cache errors
523
565
524
566
### CacheStrategy Enum
525
567
@@ -532,6 +574,31 @@ enum CacheStrategy {
532
574
}
533
575
```
534
576
577
+
### CacheError Class
578
+
579
+
Error information for cache operations.
580
+
581
+
```dart
582
+
class CacheError {
583
+
final String key; // Cache key that failed
584
+
final CacheErrorType type; // Type of error
585
+
final Object error; // Underlying exception
586
+
final StackTrace stackTrace; // Stack trace
587
+
final Object? rawData; // Data that failed (if available)
588
+
String get message; // Human-readable error message
589
+
}
590
+
```
591
+
592
+
### CacheErrorType Enum
593
+
594
+
```dart
595
+
enum CacheErrorType {
596
+
serialization, // jsonEncode failed
597
+
deserializationJson, // jsonDecode failed
598
+
deserializationFromJson, // fromJson function threw
599
+
}
600
+
```
601
+
535
602
### CachingStats Class
536
603
537
604
Statistics about the current cache state.
@@ -548,8 +615,11 @@ class CachingStats {
548
615
549
616
## ❓ FAQ
550
617
551
-
**Q: What happens if serialization or deserialization fails?**
552
-
A: The error is logged, the cache is ignored, and the remote call is used. Your app will never crash due to cache errors.
618
+
**Q: What happens if serialization or deserialization fails?**
619
+
A: By default, the error is logged (in verbose mode), the cache is ignored, and the remote call is used. Your app will never crash due to cache errors. You can use the `onError` callback to capture and handle these errors for logging, metrics, or debugging.
620
+
621
+
**Q: How can I monitor cache errors in production?**
622
+
A: Use the `onError` callback to send errors to your analytics or monitoring service (Sentry, Datadog, etc.). The callback receives a `CacheError` object with details about the failure.
553
623
554
624
**Q: Can I use my own model classes?**
555
625
A: Yes! Just provide a `fromJson` function and ensure your model supports `toJson` when caching. The package relies on `jsonEncode` / `jsonDecode` under the hood.
0 commit comments