Cached
A lazily-computed, invalidatable single value, i.e. a memoized version of a () -> T generator.
Unlike Kotlin's stdlib lazy { ... } delegate, a Cached value can be explicitly invalidated and later regenerated on demand, which makes it suitable for values that are expensive to compute but occasionally need to be recomputed (e.g. because some external state they depend on has changed). Use Cached.of to wrap a generator function:
val cached: Cached<T> = Cached.of { computeExpensiveValue() }
cached.value // computes and caches the value on first access
cached.invalidate() // forces the next access to recompute the valueContent copied to clipboard
Type Parameters
T
is the type of the cached value
Inheritors
Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Ensures the cached value is up-to-date (see regenerate), then applies consumer to it, returning the result of consumer.