Class DefaultSimpleCache<K extends Serializable,​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 Serializable,​V>
    extends Object
    implements org.alfresco.repo.cache.SimpleCache<K,​V>, org.springframework.beans.factory.BeanNameAware
    SimpleCache implementation backed by a Google Cache implementation.
    Author:
    Matt Ward
    • Constructor Detail

      • 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 = use DEFAULT_CAPACITY
        useMaxItems - Whether the maxItems value should be applied as a size-cap for the cache.
        cacheName - An arbitrary cache name.
      • DefaultSimpleCache

        public DefaultSimpleCache​(int maxItems,
                                  String cacheName)
        Create a size limited, named cache with no other features enabled.
        Parameters:
        maxItems - int
        cacheName - String
      • DefaultSimpleCache

        public DefaultSimpleCache()
        Default constructor. Initialises the cache with no size limit and no name.
    • Method Detail

      • contains

        public boolean contains​(K key)
        Specified by:
        contains in interface org.alfresco.repo.cache.SimpleCache<K extends Serializable,​V>
      • getKeys

        public Collection<K> getKeys()
        Specified by:
        getKeys in interface org.alfresco.repo.cache.SimpleCache<K extends Serializable,​V>
      • get

        public V get​(K key)
        Specified by:
        get in interface org.alfresco.repo.cache.SimpleCache<K extends Serializable,​V>
      • put

        public void put​(K key,
                        V value)
        Specified by:
        put in interface org.alfresco.repo.cache.SimpleCache<K extends Serializable,​V>
      • putAndCheckUpdate

        public boolean putAndCheckUpdate​(K key,
                                         V value)
        put method that may be used to check for updates in a thread-safe manner.
        Returns:
        true if the put resulted in a change in value, false otherwise.
      • remove

        public void remove​(K key)
        Specified by:
        remove in interface org.alfresco.repo.cache.SimpleCache<K extends Serializable,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface org.alfresco.repo.cache.SimpleCache<K extends Serializable,​V>
      • 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 String getCacheName()
        Retrieve the name of this cache.
        Returns:
        the cacheName
        See Also:
        setCacheName(String)
      • setCacheName

        public void setCacheName​(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​(String cacheName)
        Since there are many cache instances, it is useful to be able to associate a name with each one.
        Specified by:
        setBeanName in interface org.springframework.beans.factory.BeanNameAware
        Parameters:
        cacheName - Set automatically by Spring, but can be set manually if required.