ValueWrapper class final

A value found in a cache, wrapped so that a stored null can be told apart from a missing entry.

Cache.get returns a ValueWrapper for a hit and null for a miss. Without the wrapper a method whose result was null would look uncached and run again every time. You meet it when you read a cache by hand or write a Cache of your own: return ValueWrapper(value) for a hit (also when value is null) and null for a miss.

// An admin page shows what is cached for one isbn.
final wrapper = cacheManager.getCache('books')!.get('978-0');
if (wrapper != null) {
  log.info(wrapper.value); // may be null: null was cached
}

Spring (Java):

Cache.ValueWrapper wrapper = cache.get("978-0");
if (wrapper != null) log.info("{}", wrapper.get());

Constructors

ValueWrapper(Object? value)
Wraps value, which may be null.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value → Object?
The cached value; null when null was stored.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited