cached_resource library

Classes

CachedResource<K, V>
Cached resource implementation based on NetworkBoundResource to follow the single source of truth principle.
CacheDuration<K, V>
Helper class to check if cache is stale
CacheEntry<V>
Base cache entry
JsonStorageAdapter<V>
Helper class for toJson/fromJson conversion using provided executor and decode.
MemoryResourceStorage<K, V>
Simple in-memory key-value resource storage
MemoryResourceStorageProvider
Factory to provide instance of MemoryResourceStorage.
OffsetPageableResource<K, V>
Cached resource that allows pageable loading.
PageableData<V>
Base class to represent pageable data.
PageableDataFactory<V>
Factory to create PageableData. The default factory creates PageableData with loadedAll and items fields. If you need to add more fields to PageableData then you need to provide a custom factory. The custom factory should extend this class and override create method. V - type of items in PageableData.
PageableResponse<V, R>
Represents pageable data with items and optional meta information. Meta information can be used to store additional data like total count, etc.
Resource<T>
Resource representation that can have a few states:
ResourceConfig
Global config for CachedResource
ResourceLogger
Base interface of Logger with default implementation
ResourceStorage<K, V>
Base interface for resource cache storage
ResourceStorageProvider
Interface for resource storage factory
SizePageableData<V>
Base class to represent pageable data.
SizePageableDataFactory<V>
Factory to create SizePageableData. The default factory creates SizePageableData with loadedAll and items fields. If you need to add more fields to SizePageableData then you need to provide a custom factory. The custom factory should extend this class and override create method. V - type of items in SizePageableData.
SizePageableResource<K, V, R>
Cached resource that allows pageable loading by page and size.
TimestampProvider
Helper class to provide timestamp in milliseconds from the Unix epoch Can be used to define custom timestamp logic in tests

Enums

LoggerLevel
The severity level for log entry
ResourceState

Constants

defaultIntersectionCount → const int
Default negative shift in offset value during page loading.
defaultPageableResourcePageSize → const int
Default page size for SizePageableResource
defaultResourcePageSize → const int
Default page size for OffsetPageableResource

Functions

syncStorageExecutor<T>(FutureOr<T> task()) FutureOr<T>
Synchronous task executor that just calls a task

Typedefs

CheckIsCacheStale<K, V> = bool Function(K key, CacheEntry<V> cache, TimestampProvider timestampProvider)
Delegate for CacheDuration to check if cache is stale
DurationResolver<K, V> = CacheDuration<K, V> Function(K key, CacheEntry<V> cache)
Dynamic CacheDuration resolver
LoadPageableCallback<K, V, R> = Future<PageableResponse<V, R>> Function(K key, int page, int size)
Callback to load items from the external source (server api, etc.) Page starts from 1.
LoadPageCallback<K, V> = Future<List<V>> Function(K key, int offset, int limit)
Callback to load items from the external source (server api, etc.)
OffsetPageableData<V> = PageableData<V>
OffsetPageableDataFactory<V> = PageableDataFactory<V>
StorageDecoder<V> = FutureOr<V> Function(dynamic storedValue)
Base interface for persistent storage decoding.
StorageExecutor = FutureOr<T> Function<T>(FutureOr<T> task())
Interface for task executor that can be provided externally

Exceptions / Errors

InconsistentPageDataException
Exception that throws in case when inconsistent page data detected. Usually it means that data on the server was changed and we need to reload all items from the first page.