ModelCache<T extends DBModelI> class
Create a memory cache for Models. For this module to work correctly Firebase cache has to be turned on. (It is automatically on unless you change Firebase configuration to turn it off)
This will store the fetches done through here in memory.
If it is not in memory, this loads data from firebase cache. And will store the data in memory for later fetches.
If it is not available in firebase cache also it will get the data from online Firestore and save in memory for later user.
In any of the above cases, if the data fetched is older than
_timeout
minutes, it will send a request to get the data from online
Firestore from the background and store it in the memory. So the data
will be available in the next time you fetch.
Before using ModelCache with a specific DBModelI implementation,
configurations for that specific DBModelI has to be set through
ModelCacheSettings
. Otherwise this will throw an Exception.
See Also:
ModelCacheSettings
- Store the setting information for each DBModelI
RepositoryAddon - Used to fetch data from DocumentReference
FirebaseRepository - Used to fetch data from Firestore and wrap
them in models.
Constructors
- ModelCache()
-
Create a memory cache for Models. For this module to work correctly
Firebase cache has to be turned on. (It is automatically on unless
you change Firebase configuration to turn it off)
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clearMem(
) → void - Clear memory cache
-
fetch(
DocumentReference< Object?> ref) → Future<T> - Fetch data from
-
fromMem(
DocumentReference< Object?> ref) → T? - Get the cached data directly from memory
-
multiFetch(
Iterable< DocumentReference< refs) → Future<Object?> >List< T> > -
Same as fetch but for multiple list of
DocumentReference
s,refs
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
setSettings<
T extends DBModelI> ({required RepositoryAddon< T> addon, int timeout = 60}) → void - Store the settings provided for a specific type of DBModelI.