Package org.nuxeo.ecm.core.cache
Class InMemoryCacheImpl
- java.lang.Object
-
- org.nuxeo.ecm.core.cache.AbstractCache
-
- org.nuxeo.ecm.core.cache.InMemoryCacheImpl
-
- All Implemented Interfaces:
Cache
,CacheManagement
public class InMemoryCacheImpl extends AbstractCache
Default in memory implementation for cache management based on guava- Since:
- 6.0
-
-
Field Summary
Fields Modifier and Type Field Description protected com.google.common.cache.Cache<String,Serializable>
cache
-
Fields inherited from class org.nuxeo.ecm.core.cache.AbstractCache
name, ttl
-
-
Constructor Summary
Constructors Constructor Description InMemoryCacheImpl(CacheDescriptor desc)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Serializable
get(String key)
Get method to retrieve value from cache Must not raise exception if the key is null, but return nulllong
getSize()
Returns this cache size (approximate number of entries), or-1
if the number of entries is unknown or too expensive to compute.boolean
hasEntry(String key)
Check if a given key is present inside the cache.void
invalidate(String key)
Invalidate the given keyvoid
invalidateAll()
Invalidate all key-value stored in the cachevoid
invalidateLocal(String key)
Invalidates the given key locally.void
invalidateLocalAll()
Invalidates all keys locally.Set<String>
keySet()
Returns the set of all keys stored in the cache.void
put(String key, Serializable value)
Put method to store aSerializable
valuevoid
putLocal(String key, Serializable value)
Stores aSerializable
value into the cache locally.-
Methods inherited from class org.nuxeo.ecm.core.cache.AbstractCache
getName, start, stop, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.nuxeo.ecm.core.cache.Cache
computeIfAbsent
-
-
-
-
Field Detail
-
cache
protected final com.google.common.cache.Cache<String,Serializable> cache
-
-
Constructor Detail
-
InMemoryCacheImpl
public InMemoryCacheImpl(CacheDescriptor desc)
-
-
Method Detail
-
get
public Serializable get(String key)
Description copied from interface:Cache
Get method to retrieve value from cache Must not raise exception if the key is null, but return null- Parameters:
key
- the string key- Returns:
- the
Serializable
value, return null if the key does not exist or if the key is null
-
keySet
public Set<String> keySet()
Description copied from interface:Cache
Returns the set of all keys stored in the cache.- Returns:
- the
Set
of all keys
-
invalidate
public void invalidate(String key)
Description copied from interface:Cache
Invalidate the given key- Parameters:
key
- , the key to remove from the cache, if null will do nothing
-
invalidateLocal
public void invalidateLocal(String key)
Description copied from interface:CacheManagement
Invalidates the given key locally. Does not propagate invalidations.- Parameters:
key
- the key to remove from the cache
-
invalidateAll
public void invalidateAll()
Description copied from interface:Cache
Invalidate all key-value stored in the cache
-
invalidateLocalAll
public void invalidateLocalAll()
Description copied from interface:CacheManagement
Invalidates all keys locally. Does not propagate invalidations.
-
put
public void put(String key, Serializable value)
Description copied from interface:Cache
Put method to store aSerializable
value- Parameters:
key
- the string key, if null, the value will not be storedvalue
- the value to store, if null, the value will not be stored
-
putLocal
public void putLocal(String key, Serializable value)
Description copied from interface:CacheManagement
Stores aSerializable
value into the cache locally. Does not propagate invalidations.- Parameters:
key
- the keyvalue
- the value
-
hasEntry
public boolean hasEntry(String key)
Description copied from interface:Cache
Check if a given key is present inside the cache. Compared to the get() method, this method must not update internal cache state and change TTL- Parameters:
key
- the string key- Returns:
- true if a corresponding entry exists, false otherwise
-
getSize
public long getSize()
Description copied from interface:CacheManagement
Returns this cache size (approximate number of entries), or-1
if the number of entries is unknown or too expensive to compute.- Returns:
- the approximate number of entries, or
-1
-
-