simple<CacheContentType> static method
SimpleCachedValue<CacheContentType>
simple<CacheContentType>(
- ComputeCacheCallback<
CacheContentType> callback
Creates a CachedValue that is only manually invalidated. The main CachedValue constructor is a shorthand for this method.
This cache type will only be considered invalid if invalidate is called manually.
Usage example:
int factorial(int n) {
if (n < 0) throw ('Negative numbers are not allowed.');
return n <= 1 ? 1 : n * factorial(n - 1);
}
int originalValue =1;
final factorialCache = CachedValue.simple(() => factorial(originalValue));
print(factorialCache.value); // 1
originalValue = 6;
print(factorialCache.value); // 1
factorialCache.invalidate();
print(factorialCache.value); // 720
See also:
- CachedValue.dependent that creates a cache that is updated if a dependency changes.
Implementation
static SimpleCachedValue<CacheContentType> simple<CacheContentType>(
ComputeCacheCallback<CacheContentType> callback) {
return SimpleCachedValue<CacheContentType>(callback);
}