DeduplicationCacheRepository<Info, DS extends DataSourceCallable<Info> > class
abstract
The most complete Repository implementation, combining safety, memory caching, and request deduplication.
This class is designed for high-performance data fetching where you want to minimize network overhead and ensure consistent data across the app.
The Execution Flow:
- Cache Check: If valid data exists in memory (isRefreshRequired is false), it returns immediately.
- Deduplication: If no cache exists but an identical request is already in progress, it waits for that request.
- Execution: If it's a new unique request, it calls the DataSource.
- Safety: Any exception during the process is caught and mapped to a RepositoryError.
- Update: Successful results are stored in the cache for future calls.
Generic Types:
Info: The data model type.DS: The DataSourceCallable used to fetch the data.
- Inheritance
-
- Object
- Repository
- RepositoryDataSource<
DS> - RepositoryDataSourceCallable<
Info, DS> - SafeRepositoryDatasourceCallable<
Info, DS> - SafeMemoryCacheRepository<
Info, DS> - DeduplicationCacheRepository
- Mixed-in types
-
- DeduplicationManagement<
Info, DS>
- DeduplicationManagement<
Constructors
- DeduplicationCacheRepository({required DS dataSource, required Duration refreshDuration})
- Creates a DeduplicationCacheRepository.
Properties
- cache ↔ Info?
-
Retrieves the cached data if available. Updates lastRetry.
getter/setter pairinherited
- dataSource → DS
-
The DataSource instance used by this repository to fetch or persist data.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- lastRetry ↔ DateTime?
-
The timestamp of the last attempt to access the cache.
getter/setter pairinherited
- observer → SafeCallableRepositoryObserver
-
no setterinherited
- onException → RepositoryError Function(Object exception, StackTrace stackTrace)
-
Default handler for unexpected exceptions (e.g., parsing errors).
Logs the error and returns OnExceptionRepositoryError.
no setterinherited
- onInadmissibleException → RepositoryError Function(InadmissibleDataSourceException exception, StackTrace stackTrace)
-
Default handler for inadmissible exceptions (e.g., 404 Not Found).
Logs the error and returns InadmissibleRepositoryError.
no setterinherited
- onUnControlException → RepositoryError Function(UnControlDataSourceException exception, StackTrace stackTrace)
-
Default handler for uncontrolled exceptions (e.g., 500 Internal Server Error).
Logs the error and returns UnControlRepositoryError.
no setterinherited
- refreshDuration → Duration
-
The duration for which the cache is considered valid.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- timeStamp ↔ DateTime?
-
The timestamp when the cache was last updated.
getter/setter pairinherited
Methods
-
call(
{required covariant Params repositoryParams}) → Future< Either< RepositoryError, Info> > -
Overrides the repository call to apply deduplication.
inherited
-
clear(
) → void -
Clears the cache and resets timestamps.
inherited
-
dispose(
) → void -
Frees up resources and notifies the observer.
inherited
-
isCached(
) → bool -
Returns
trueif there is data in the cache (regardless of expiration).inherited -
isRefreshRequired(
) → bool -
Checks if the cache needs to be refreshed.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refreshCache(
{required Either< RepositoryError, Info> datasourceResponse}) → Info? -
Extracts the data from the response to update the cache.
inherited
-
safeCall(
{required FutureOr< Either< call()}) → FutureOr<RepositoryError, Info> >Either< RepositoryError, Info> > -
Executes a function safely, catching defined exceptions and mapping them to Left.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited