SafeMemoryCacheRepository<Info, DS extends DataSourceCallable<Info> > class
abstract
A SafeRepositoryDatasourceCallable that implements an in-memory caching strategy.
It checks for valid cached data before making a network request.
Strategy:
- Check if isRefreshRequired returns
false. - If valid cache exists, return Right with cached data immediately.
- If cache is expired or missing, call the datasource.
- If the call is successful, update the cache via refreshCache.
- Inheritance
-
- Object
- Repository
- RepositoryDataSource<
DS> - RepositoryDataSourceCallable<
Info, DS> - SafeRepositoryDatasourceCallable<
Info, DS> - SafeMemoryCacheRepository
- Mixed-in types
-
- MemoryCacheHelper<
Info>
- MemoryCacheHelper<
- Implementers
Constructors
- SafeMemoryCacheRepository({required DS dataSource, required Duration refreshDuration})
- A SafeRepositoryDatasourceCallable that implements an in-memory caching strategy.
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.
final
- 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> > -
Executes the datasource call within a safeCall block.
override
-
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.
-
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