public class GuavaCache extends Object implements org.springframework.cache.Cache
Cache adapter implementation on top of a
Guava Cache instance.
Requires Google Guava 12.0 or higher.
| Constructor and Description |
|---|
GuavaCache(String name,
com.google.common.cache.Cache<Object,Object> cache)
Create a
GuavaCache instance with the specified name and the
given internal Cache to use. |
GuavaCache(String name,
com.google.common.cache.Cache<Object,Object> cache,
boolean allowNullValues)
Create a
GuavaCache instance with the specified name and the
given internal Cache to use. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
void |
evict(Object key) |
protected Object |
fromStoreValue(Object storeValue)
Convert the given value from the internal store to a user value
returned from the get method (adapting
null). |
org.springframework.cache.Cache.ValueWrapper |
get(Object key) |
<T> T |
get(Object key,
Class<T> type) |
String |
getName() |
com.google.common.cache.Cache<Object,Object> |
getNativeCache() |
boolean |
isAllowNullValues() |
void |
put(Object key,
Object value) |
org.springframework.cache.Cache.ValueWrapper |
putIfAbsent(Object key,
Object value) |
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). |
public GuavaCache(String name, com.google.common.cache.Cache<Object,Object> cache)
GuavaCache instance with the specified name and the
given internal Cache to use.name - the name of the cachecache - the backing Guava Cache instancepublic GuavaCache(String name, com.google.common.cache.Cache<Object,Object> cache, boolean allowNullValues)
GuavaCache instance with the specified name and the
given internal Cache to use.name - the name of the cachecache - the backing Guava Cache instanceallowNullValues - whether to accept and convert null
values for this cachepublic final String getName()
getName in interface org.springframework.cache.Cachepublic final com.google.common.cache.Cache<Object,Object> getNativeCache()
getNativeCache in interface org.springframework.cache.Cachepublic final boolean isAllowNullValues()
public org.springframework.cache.Cache.ValueWrapper get(Object key)
get in interface org.springframework.cache.Cachepublic <T> T get(Object key, Class<T> type)
get in interface org.springframework.cache.Cachepublic void put(Object key, Object value)
put in interface org.springframework.cache.Cachepublic org.springframework.cache.Cache.ValueWrapper putIfAbsent(Object key, Object value)
putIfAbsent in interface org.springframework.cache.Cachepublic void evict(Object key)
evict in interface org.springframework.cache.Cachepublic void clear()
clear in interface org.springframework.cache.Cacheprotected Object fromStoreValue(Object storeValue)
null).storeValue - the store value