CachedValue<CacheContentType> constructor

CachedValue<CacheContentType>(
  1. ComputeCacheCallback<CacheContentType> callback
)

Creates a CachedValue that is only manually invalidated.

The implementation type for the returned value is SimpleCachedValue.

This cache type will only be considered invalid if invalidate is called manually (or by a SingleChildCachedValue that wraps a cache of this type).

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(() => factorial(originalValue));
print(factorialCache.value); // 1

originalValue = 6;

print(factorialCache.value); // 1
factorialCache.invalidate();

print(factorialCache.value); // 720

See also:

Implementation

factory CachedValue(ComputeCacheCallback<CacheContentType> callback) {
  return SimpleCachedValue<CacheContentType>(callback);
}