Package org.alfresco.repo.cache
Class DefaultSimpleCache<K extends Serializable,V>
java.lang.Object
org.alfresco.repo.cache.DefaultSimpleCache<K,V>
- All Implemented Interfaces:
SimpleCache<K,,V> org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware
public final class DefaultSimpleCache<K extends Serializable,V>
extends Object
implements SimpleCache<K,V>, org.springframework.beans.factory.BeanNameAware
SimpleCache implementation backed by a Google Cache implementation.- Author:
- Matt Ward
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.DefaultSimpleCache(int maxItems, boolean useMaxItems, int ttlSecs, int maxIdleSecs, String cacheName) Construct a cache using the specified capacity and name.DefaultSimpleCache(int maxItems, String cacheName) Create a size limited, named cache with no other features enabled. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleanRetrieve the name of this cache.getKeys()intGet the time-to-idle setting in seconds.intGets the maximum number of items that the cache will hold.intGet the time-to-live setting in seconds.booleanIs a size-cap in use?voidbooleanputAndCheckUpdate(K key, V value) putmethod that may be used to check for updates in a thread-safe manner.voidvoidsetBeanName(String cacheName) Since there are many cache instances, it is useful to be able to associate a name with each one.voidsetCacheName(String cacheName) Since there are many cache instances, it is useful to be able to associate a name with each one.toString()
-
Constructor Details
-
DefaultSimpleCache
public DefaultSimpleCache(int maxItems, boolean useMaxItems, int ttlSecs, int maxIdleSecs, 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
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 Details
-
contains
- Specified by:
containsin interfaceSimpleCache<K extends Serializable,V>
-
getKeys
- Specified by:
getKeysin interfaceSimpleCache<K extends Serializable,V>
-
get
- Specified by:
getin interfaceSimpleCache<K extends Serializable,V>
-
put
- Specified by:
putin interfaceSimpleCache<K extends Serializable,V>
-
putAndCheckUpdate
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
- Specified by:
removein interfaceSimpleCache<K extends Serializable,V>
-
clear
public void clear()- Specified by:
clearin interfaceSimpleCache<K extends Serializable,V>
-
toString
-
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
Retrieve the name of this cache.- Returns:
- the cacheName
- See Also:
-
setCacheName
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
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.
-