java.lang.Object | |
↳ | org.springframework.util.CachingMapDecorator<K, V> |
A simple decorator for a Map, encapsulating the workflow for caching expensive values in a target Map. Supports caching weak or strong keys.
This class is an abstract template. Caching Map implementations
should subclass and override the create(key)
method which
encapsulates expensive creation of a new object.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a CachingMapDecorator with strong keys,
using an underlying synchronized Map.
| |||||||||||
Create a CachingMapDecorator,
using an underlying synchronized Map.
| |||||||||||
Create a CachingMapDecorator with initial size,
using an underlying synchronized Map.
| |||||||||||
Create a CachingMapDecorator for the given Map.
| |||||||||||
Create a CachingMapDecorator for the given Map.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Get value for key.
| |||||||||||
Put an object into the cache, possibly wrapping it with a weak
reference.
| |||||||||||
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a value to cache for the given key.
| |||||||||||
Decide whether to use a weak reference for the value of
the given key-value pair.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
|
Create a CachingMapDecorator with strong keys, using an underlying synchronized Map.
Create a CachingMapDecorator, using an underlying synchronized Map.
weak | whether to use weak references for keys and values |
---|
Create a CachingMapDecorator with initial size, using an underlying synchronized Map.
weak | whether to use weak references for keys and values |
---|---|
size | the initial cache size |
Create a CachingMapDecorator for the given Map.
The passed-in Map won't get synchronized explicitly, so make sure to pass in a properly synchronized Map, if desired.
targetMap | the Map to decorate |
---|
Create a CachingMapDecorator for the given Map.
The passed-in Map won't get synchronized explicitly unless you specify "synchronize" as "true".
targetMap | the Map to decorate |
---|---|
synchronize | whether to synchronize on the given Map |
weak | whether to use weak references for values |
Get value for key. Creates and caches value if it doesn't already exist in the cache.
This implementation is not synchronized: This is highly concurrent but does not guarantee unique instances in the cache, as multiple values for the same key could get created in parallel. Consider overriding this method to synchronize it, if desired.
Put an object into the cache, possibly wrapping it with a weak reference.
Create a value to cache for the given key.
Called by get
if there is no value cached already.
key | the cache key |
---|
Decide whether to use a weak reference for the value of the given key-value pair.
key | the candidate key |
---|---|
value | the candidate value |
true
in order to use a weak reference;
false
otherwise.