Class ConcurrentFIFOExoCache<K extends Serializable,V>

java.lang.Object
org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache<K,V>
All Implemented Interfaces:
ExoCache<K,V>
Direct Known Subclasses:
AsyncInvalidationExoCache, FIFOExoCache, SimpleExoCache, SimpleReplicatedExoCache

public class ConcurrentFIFOExoCache<K extends Serializable,V> extends Object implements ExoCache<K,V>
An ExoCache implementation based on ConcurrentHashMap that minimize locking. Cache entries are maintained in a fifo list that is used for the fifo eviction policy.
Version:
$Revision$
Author:
Julien Viet
  • Constructor Details

    • ConcurrentFIFOExoCache

      public ConcurrentFIFOExoCache()
    • ConcurrentFIFOExoCache

      public ConcurrentFIFOExoCache(org.exoplatform.services.log.Log log)
    • ConcurrentFIFOExoCache

      public ConcurrentFIFOExoCache(int maxSize)
    • ConcurrentFIFOExoCache

      public ConcurrentFIFOExoCache(int maxSize, org.exoplatform.services.log.Log log)
    • ConcurrentFIFOExoCache

      public ConcurrentFIFOExoCache(String name, int maxSize)
    • ConcurrentFIFOExoCache

      public ConcurrentFIFOExoCache(String name, int maxSize, org.exoplatform.services.log.Log log)
  • Method Details

    • assertConsistent

      public void assertConsistent()
    • getName

      public String getName()
      Description copied from interface: ExoCache
      Returns the cache name
      Specified by:
      getName in interface ExoCache<K extends Serializable,V>
      Returns:
      the cache name
    • setName

      public void setName(String s)
      Description copied from interface: ExoCache
      Sets the cache name.
      Specified by:
      setName in interface ExoCache<K extends Serializable,V>
      Parameters:
      s - the cache name
    • getLabel

      public String getLabel()
      Description copied from interface: ExoCache
      Returns the cache label
      Specified by:
      getLabel in interface ExoCache<K extends Serializable,V>
      Returns:
      the cache label
    • setLabel

      public void setLabel(String name)
      Description copied from interface: ExoCache
      Sets the cache label
      Specified by:
      setLabel in interface ExoCache<K extends Serializable,V>
      Parameters:
      name - the cache label
    • getLiveTime

      public long getLiveTime()
      Description copied from interface: ExoCache
      Returns the maximum life time of an entry in the cache. The life time is a value in seconds, a negative value means that the life time is infinite.
      Specified by:
      getLiveTime in interface ExoCache<K extends Serializable,V>
      Returns:
      the live time
    • setLiveTime

      public void setLiveTime(long period)
      Description copied from interface: ExoCache
      Sets the maximum life time of an entry in the cache.
      Specified by:
      setLiveTime in interface ExoCache<K extends Serializable,V>
      Parameters:
      period - the live time
    • getLiveTimeMillis

      public long getLiveTimeMillis()
    • setLiveTimeMillis

      public void setLiveTimeMillis(long liveTimeMillis)
    • getMaxSize

      public int getMaxSize()
      Description copied from interface: ExoCache
      Returns the maximum capacity of the cache.
      Specified by:
      getMaxSize in interface ExoCache<K extends Serializable,V>
      Returns:
      the maximum capacity
    • setMaxSize

      public void setMaxSize(int max)
      Description copied from interface: ExoCache
      Sets the maximum capacity of the cache.
      Specified by:
      setMaxSize in interface ExoCache<K extends Serializable,V>
      Parameters:
      max - the maximum capacity
    • get

      public V get(Serializable name)
      Description copied from interface: ExoCache
      Performs a lookup operation.
      Specified by:
      get in interface ExoCache<K extends Serializable,V>
      Parameters:
      name - the cache key
      Returns:
      the cached value which may be evaluated to null
    • put

      public void put(K name, V obj)
      Description copied from interface: ExoCache
      Performs a put in the cache.
      Specified by:
      put in interface ExoCache<K extends Serializable,V>
      Parameters:
      name - the cache key
      obj - the cached value
    • putLocal

      public void putLocal(K name, V obj)
      Description copied from interface: ExoCache
      Performs a put in the cache local mode (avoid replication).
      Specified by:
      putLocal in interface ExoCache<K extends Serializable,V>
      Parameters:
      name - the cache key
      obj - the cached value
    • putMap

      public void putMap(Map<? extends K,? extends V> objs)
      Description copied from interface: ExoCache
      Performs a put of all the entries provided by the map argument.
      Specified by:
      putMap in interface ExoCache<K extends Serializable,V>
      Parameters:
      objs - the objects to put
    • remove

      public V remove(Serializable name)
      Description copied from interface: ExoCache
      Removes an entry from the cache.
      Specified by:
      remove in interface ExoCache<K extends Serializable,V>
      Parameters:
      name - the cache key
      Returns:
      the previously cached value or null if no entry existed or that entry value was evaluated to null
    • getCachedObjects

      public List<? extends V> getCachedObjects()
      Description copied from interface: ExoCache
      Returns a list of cached object that are considered as valid when the method is called. Any non valid object will not be returned.
      Specified by:
      getCachedObjects in interface ExoCache<K extends Serializable,V>
      Returns:
      the list of cached objects
    • removeCachedObjects

      public List<? extends V> removeCachedObjects()
      Description copied from interface: ExoCache
      Clears the cache and returns the list of cached object that are considered as valid when the method is called. Any non valid object will not be returned.
      Specified by:
      removeCachedObjects in interface ExoCache<K extends Serializable,V>
      Returns:
      the list of cached objects
    • clearCache

      public void clearCache()
      Description copied from interface: ExoCache
      Clears the cache.
      Specified by:
      clearCache in interface ExoCache<K extends Serializable,V>
    • select

      public void select(CachedObjectSelector<? super K,? super V> selector) throws Exception
      Description copied from interface: ExoCache
      Selects a subset of the cache.
      Specified by:
      select in interface ExoCache<K extends Serializable,V>
      Parameters:
      selector - the selector
      Throws:
      Exception - any exception
    • getCacheSize

      public int getCacheSize()
      Description copied from interface: ExoCache
      Returns the number of entries in the cache.
      Specified by:
      getCacheSize in interface ExoCache<K extends Serializable,V>
      Returns:
      the size of the cache
    • getCacheHit

      public int getCacheHit()
      Description copied from interface: ExoCache
      Returns the number of time the cache was queried and a valid entry was returned.
      Specified by:
      getCacheHit in interface ExoCache<K extends Serializable,V>
      Returns:
      the cache hits
    • getCacheMiss

      public int getCacheMiss()
      Description copied from interface: ExoCache
      Returns the number of time the cache was queried and no entry was returned.
      Specified by:
      getCacheMiss in interface ExoCache<K extends Serializable,V>
      Returns:
      the cache misses
    • addCacheListener

      public void addCacheListener(CacheListener<? super K,? super V> listener)
      Description copied from interface: ExoCache
      Add a listener.
      Specified by:
      addCacheListener in interface ExoCache<K extends Serializable,V>
      Parameters:
      listener - the listener to add
    • isLogEnabled

      public boolean isLogEnabled()
      Specified by:
      isLogEnabled in interface ExoCache<K extends Serializable,V>
    • setLogEnabled

      public void setLogEnabled(boolean logEnabled)
      Specified by:
      setLogEnabled in interface ExoCache<K extends Serializable,V>
    • onExpire

      public void onExpire(K key, V obj)
      Description copied from interface: ExoCache
      On expire entry event
      Specified by:
      onExpire in interface ExoCache<K extends Serializable,V>
      Parameters:
      key - entry key
      obj - value
    • onRemove

      public void onRemove(K key, V obj)
      Description copied from interface: ExoCache
      On remove entry event
      Specified by:
      onRemove in interface ExoCache<K extends Serializable,V>
      Parameters:
      key - entry key
      obj - value
    • onPut

      public void onPut(K key, V obj)
      Description copied from interface: ExoCache
      On put entry event
      Specified by:
      onPut in interface ExoCache<K extends Serializable,V>
      Parameters:
      key - entry key
      obj - value
    • onPutLocal

      public void onPutLocal(K key, V obj)
      Description copied from interface: ExoCache
      On put entry event
      Specified by:
      onPutLocal in interface ExoCache<K extends Serializable,V>
      Parameters:
      key - entry key
      obj - value
    • onGet

      public void onGet(K key, V obj)
      Description copied from interface: ExoCache
      On get entry event
      Specified by:
      onGet in interface ExoCache<K extends Serializable,V>
      Parameters:
      key - entry key
      obj - value
    • onClearCache

      public void onClearCache()
      Description copied from interface: ExoCache
      on clear cache event
      Specified by:
      onClearCache in interface ExoCache<K extends Serializable,V>
    • getListeners

      public List<ListenerContext<K,V>> getListeners()