Cached class

Cached

Annotation for Cached package.

Method decorator that flag it as needing to be processed by Cached code generator.

Throws an InvalidGenerationSourceError

  • if we have multiple IgnoreCache annotations in method

Example

Use @cached annotation

@cached
Future<SomeResponseType> getSthData() {
  return dataSource.getData();
}

or with parameters

@Cached(syncWrite: true, ttl: 30, limit: 10, where: _checkIfShouldCache,)
Future<SomeResponseType> getSthData() {
  return dataSource.getData();
}

if you want to clear cache method use ClearCached or ClearAllCached annotation

Annotations
  • @Target({TargetKind.method, TargetKind.getter})

Constructors

Cached({int? limit, bool? syncWrite, int? ttl, Function? where, bool? persistentStorage})
Cached
const

Properties

hashCode int
The hash code for this object.
no setterinherited
limit int?
limit how many results for different method call arguments combination will be cached. Default value null, means no limit.
final
persistentStorage bool?
Defines optional usage of external persistent storage (e.g. shared preferences)
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
syncWrite bool?
Affects only async methods (those one that returns Future) If set to true first method call will be cached, and if following ( the same ) call will occur, all of them will get result from the first call. Default value is set to false.
final
ttl int?
time to live. In seconds. Set how long cache will be alive. Default value is set to null, means infinitive ttl.
final
where Function?
Function triggered before caching the value. Should return bool
final

Methods

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