Package org.alfresco.repo.cache
Class DefaultSimpleCache<K extends java.io.Serializable,V>
- java.lang.Object
-
- org.alfresco.repo.cache.DefaultSimpleCache<K,V>
-
- All Implemented Interfaces:
org.alfresco.repo.cache.SimpleCache<K,V>,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware
public final class DefaultSimpleCache<K extends java.io.Serializable,V> extends java.lang.Object implements org.alfresco.repo.cache.SimpleCache<K,V>, org.springframework.beans.factory.BeanNameAwareSimpleCacheimplementation backed by a GoogleCacheimplementation.- Author:
- Matt Ward
-
-
Constructor Summary
Constructors Constructor Description DefaultSimpleCache()Default constructor.DefaultSimpleCache(int maxItems, boolean useMaxItems, int ttlSecs, int maxIdleSecs, java.lang.String cacheName)Construct a cache using the specified capacity and name.DefaultSimpleCache(int maxItems, java.lang.String cacheName)Create a size limited, named cache with no other features enabled.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontains(K key)Vget(K key)java.lang.StringgetCacheName()Retrieve the name of this cache.java.util.Collection<K>getKeys()intgetMaxIdleSecs()Get the time-to-idle setting in seconds.intgetMaxItems()Gets the maximum number of items that the cache will hold.intgetTTLSecs()Get the time-to-live setting in seconds.booleanisUseMaxItems()Is a size-cap in use?voidput(K key, V value)booleanputAndCheckUpdate(K key, V value)putmethod that may be used to check for updates in a thread-safe manner.voidremove(K key)voidsetBeanName(java.lang.String cacheName)Since there are many cache instances, it is useful to be able to associate a name with each one.voidsetCacheName(java.lang.String cacheName)Since there are many cache instances, it is useful to be able to associate a name with each one.java.lang.StringtoString()
-
-
-
Constructor Detail
-
DefaultSimpleCache
public DefaultSimpleCache(int maxItems, boolean useMaxItems, int ttlSecs, int maxIdleSecs, java.lang.String cacheName)Construct a cache using the specified capacity and name.- Parameters:
maxItems- The cache capacity. 0 = useDEFAULT_CAPACITYuseMaxItems- Whether the maxItems value should be applied as a size-cap for the cache.cacheName- An arbitrary cache name.
-
DefaultSimpleCache
public DefaultSimpleCache(int maxItems, java.lang.String cacheName)Create a size limited, named cache with no other features enabled.- Parameters:
maxItems- intcacheName- String
-
DefaultSimpleCache
public DefaultSimpleCache()
Default constructor. Initialises the cache with no size limit and no name.
-
-
Method Detail
-
contains
public boolean contains(K key)
-
getKeys
public java.util.Collection<K> getKeys()
-
putAndCheckUpdate
public boolean putAndCheckUpdate(K key, V value)
putmethod that may be used to check for updates in a thread-safe manner.- Returns:
trueif the put resulted in a change in value,falseotherwise.
-
remove
public void remove(K key)
-
clear
public void clear()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getMaxItems
public int getMaxItems()
Gets the maximum number of items that the cache will hold.- Returns:
- maxItems
-
isUseMaxItems
public boolean isUseMaxItems()
Is a size-cap in use?- Returns:
- useMaxItems
-
getTTLSecs
public int getTTLSecs()
Get the time-to-live setting in seconds.- Returns:
- ttlSecs
-
getMaxIdleSecs
public int getMaxIdleSecs()
Get the time-to-idle setting in seconds.- Returns:
- maxIdleSecs
-
getCacheName
public java.lang.String getCacheName()
Retrieve the name of this cache.- Returns:
- the cacheName
- See Also:
setCacheName(String)
-
setCacheName
public void setCacheName(java.lang.String cacheName)
Since there are many cache instances, it is useful to be able to associate a name with each one.- Parameters:
cacheName- String- See Also:
setBeanName(String)
-
setBeanName
public void setBeanName(java.lang.String cacheName)
Since there are many cache instances, it is useful to be able to associate a name with each one.- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware- Parameters:
cacheName- Set automatically by Spring, but can be set manually if required.
-
-