Top Description Fields Constructors Methods
org.springframework.cache.support

public abstract Class AbstractValueAdaptingCache

extends Object
implements Cache
Class Inheritance
All Implemented Interfaces
org.springframework.cache.Cache
Known Direct Subclasses
org.springframework.cache.concurrent.ConcurrentMapCache
Imports
org.springframework.cache.Cache, org.springframework.lang.Nullable

Common base class for Cache implementations that need to adapt null values (and potentially other such special values) before passing them on to the underlying store.

Transparently replaces given null user values with an internal NullValue#INSTANCE, if configured to support null values (as indicated by isAllowNullValues()).

Author
Juergen Hoeller
Since
4.2.2

Field Summary

Modifier and TypeField and Description
private final boolean

Constructor Summary

AccessConstructor and Description
protected
AbstractValueAdaptingCache(boolean
whether to allow for null values
allowNullValues
)

Create an AbstractValueAdaptingCache with the given setting.

Method Summary

Modifier and TypeMethod and Description
protected Object

Returns:

the value to return to the user
fromStoreValue
(Object
the store value
storeValue
)

Convert the given value from the internal store to a user value returned from the get method (adapting null).

public Cache.ValueWrapper
get(Object
the key whose associated value is to be returned
key
)

Implements org.springframework.cache.Cache.get.

Return the value to which this cache maps the specified key.
public <T> T
get(Object
the key whose associated value is to be returned
key
,
Class<T>
the required type of the returned value (may be null to bypass a type check; in case of a null value found in the cache, the specified type is irrelevant)
type
)

Implements org.springframework.cache.Cache.get.

Return the value to which this cache maps the specified key, generically specifying a type that return value will be cast to.
public final boolean
isAllowNullValues()

Return whether null values are allowed in this cache.

protected abstract Object

Returns:

the raw store value for the key, or null if none
lookup
(Object
the key whose associated value is to be returned
key
)

Perform an actual lookup in the underlying store.

protected Object

Returns:

the value to store
toStoreValue
(Object
the given user value
userValue
)

Convert the given user value, as passed into the put method, to a value in the internal store (adapting null).

protected Cache.ValueWrapper

Returns:

the wrapped value
toValueWrapper
(Object
the original value
storeValue
)

Wrap the given store value with a SimpleValueWrapper, also going through fromStoreValue conversion.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowNullValuesback to summary
private final boolean allowNullValues

Constructor Detail

AbstractValueAdaptingCacheback to summary
protected AbstractValueAdaptingCache(boolean allowNullValues)

Create an AbstractValueAdaptingCache with the given setting.

Parameters
allowNullValues:boolean

whether to allow for null values

Method Detail

fromStoreValueback to summary
protected Object fromStoreValue(Object storeValue)

Convert the given value from the internal store to a user value returned from the get method (adapting null).

Parameters
storeValue:Object

the store value

Returns:Object

the value to return to the user

Annotations
@Nullable
getback to summary
public Cache.ValueWrapper get(Object key)

Implements org.springframework.cache.Cache.get.

Doc from org.springframework.cache.Cache.get.

Return the value to which this cache maps the specified key.

Returns null if the cache contains no mapping for this key; otherwise, the cached value (which may be null itself) will be returned in a ValueWrapper.

Parameters
key:Object

the key whose associated value is to be returned

Returns:Cache.ValueWrapper

the value to which this cache maps the specified key, contained within a ValueWrapper which may also hold a cached null value. A straight null being returned means that the cache contains no mapping for this key.

Annotations
@Override
@Nullable
getback to summary
public <T> T get(Object key, Class<T> type)

Implements org.springframework.cache.Cache.get.

Doc from org.springframework.cache.Cache.get.

Return the value to which this cache maps the specified key, generically specifying a type that return value will be cast to.

Note

This variant of get does not allow for differentiating between a cached null value and no cache entry found at all. Use the standard get(Object) variant for that purpose instead.

Parameters
key:Object

the key whose associated value is to be returned

type:Class<T>

the required type of the returned value (may be null to bypass a type check; in case of a null value found in the cache, the specified type is irrelevant)

Returns:T

the value to which this cache maps the specified key (which may be null itself), or also null if the cache contains no mapping for this key

Annotations
@Override
@SuppressWarnings:unchecked
@Nullable
isAllowNullValuesback to summary
public final boolean isAllowNullValues()

Return whether null values are allowed in this cache.

lookupback to summary
protected abstract Object lookup(Object key)

Perform an actual lookup in the underlying store.

Parameters
key:Object

the key whose associated value is to be returned

Returns:Object

the raw store value for the key, or null if none

Annotations
@Nullable
toStoreValueback to summary
protected Object toStoreValue(Object userValue)

Convert the given user value, as passed into the put method, to a value in the internal store (adapting null).

Parameters
userValue:Object

the given user value

Returns:Object

the value to store

toValueWrapperback to summary
protected Cache.ValueWrapper toValueWrapper(Object storeValue)

Wrap the given store value with a SimpleValueWrapper, also going through fromStoreValue conversion. Useful for get(Object) and putIfAbsent(Object, Object) implementations.

Parameters
storeValue:Object

the original value

Returns:Cache.ValueWrapper

the wrapped value

Annotations
@Nullable