Class MultiLruCache

  • All Implemented Interfaces:
    Cache
    Direct Known Subclasses:
    BoundedMultiLruCache

    public class MultiLruCache
    extends BaseCache
    MultiLruCache -- in-memory bounded LRU cache with multiple LRU lists Underlying Hashtable is made into logical segments, with each segment having its own LRU list.
    • Constructor Detail

      • MultiLruCache

        public MultiLruCache()
    • Method Detail

      • init

        public void init​(int maxCapacity,
                         Properties props)
                  throws Exception
        initialize the LRU cache
        Specified by:
        init in interface Cache
        Overrides:
        init in class BaseCache
        Parameters:
        maxCapacity - maximum number of entries this cache may hold
        props - opaque list of properties for a given cache implementation
        Throws:
        Exception
      • createItem

        protected BaseCache.CacheItem createItem​(int hashCode,
                                                 Object key,
                                                 Object value,
                                                 int size)
        create new item
        Overrides:
        createItem in class BaseCache
        Parameters:
        hashCode - for the entry
        key - Object key
        value - Object value
        size - size in bytes of the item subclasses may override to provide their own CacheItem extensions e.g. one that permits persistence.
      • trimLru

        protected BaseCache.CacheItem trimLru​(int segment)
        remove an lru item from one of the LRU lists
        Parameters:
        the - LRU segment index to trim
        Returns:
        the item that was successfully trimmed
      • itemAdded

        protected BaseCache.CacheItem itemAdded​(BaseCache.CacheItem item)
        this item is just added to the cache
        Overrides:
        itemAdded in class BaseCache
        Parameters:
        item - CacheItem that was created
        Returns:
        a overflow item; may be null Cache bucket is already synchronized by the caller
      • itemAccessed

        protected void itemAccessed​(BaseCache.CacheItem item)
        this item is accessed
        Overrides:
        itemAccessed in class BaseCache
        Parameters:
        item - CacheItem accessed Cache bucket is already synchronized by the caller
      • itemRefreshed

        protected void itemRefreshed​(BaseCache.CacheItem item,
                                     int oldSize)
        item value has been refreshed
        Overrides:
        itemRefreshed in class BaseCache
        Parameters:
        item - CacheItem that was refreshed
        oldSize - size of the previous value that was refreshed Cache bucket is already synchronized by the caller
      • itemRemoved

        protected void itemRemoved​(BaseCache.CacheItem item)
        item value has been removed from the cache
        Overrides:
        itemRemoved in class BaseCache
        Parameters:
        item - CacheItem that was just removed Cache bucket is already synchronized by the caller
      • handleOverflow

        protected void handleOverflow()
        cache has reached threshold so trim its size. subclasses are expected to provide a robust cache replacement algorithm.
        Overrides:
        handleOverflow in class BaseCache
      • incrementTrimIndex

        protected void incrementTrimIndex()
      • getStatByName

        public Object getStatByName​(String key)
        get the desired statistic counter
        Specified by:
        getStatByName in interface Cache
        Overrides:
        getStatByName in class BaseCache
        Parameters:
        key - to corresponding stat
        Returns:
        an Object corresponding to the stat See also: Constant.java for the key
      • getStats

        public Map getStats()
        get the stats snapshot
        Specified by:
        getStats in interface Cache
        Overrides:
        getStats in class BaseCache
        Returns:
        a Map of stats See also: Constant.java for the keys