Class OnHeapCachingTier<K,​V>

  • Type Parameters:
    K - The key type
    V - the value type
    All Implemented Interfaces:
    CachingTier<K,​V>

    public class OnHeapCachingTier<K,​V>
    extends java.lang.Object
    implements CachingTier<K,​V>
    An instance of this class will delegate the storage to the backing HeapCacheBackEnd.
    Adding :
    • making sure only a single thread populates the cache for a given key at a time
    • translate calls to the eviction listeners
    • Add all the crap about sizing and stuff
    Author:
    Alex Snaps
    • Constructor Detail

      • OnHeapCachingTier

        public OnHeapCachingTier​(HeapCacheBackEnd<K,​java.lang.Object> backEnd)
        A Constructor
        Parameters:
        backEnd - the HeapCacheBackEnd that will back this CachingTier
    • Method Detail

      • createOnHeapCache

        public static OnHeapCachingTier<java.lang.Object,​Element> createOnHeapCache​(Ehcache cache,
                                                                                          Pool onHeapPool)
        Factory method
        Parameters:
        cache - the cache we're planning to back
        onHeapPool - the pool, if any, to use
        Returns:
        the OnHeapCachingTier properly configured for this cache
      • loadOnPut

        public boolean loadOnPut()
        Description copied from interface: CachingTier
        Returns true if values should be loaded to this cache on put.

        This may be a dynamic decision, based for example on the occupancy of the cache.

        Specified by:
        loadOnPut in interface CachingTier<K,​V>
        Returns:
        true if values should be loaded on put
      • get

        public V get​(K key,
                     java.util.concurrent.Callable<V> source,
                     boolean updateStats)
        Description copied from interface: CachingTier
        Returns the value associated with the key, or populates the mapping using the Callable instance
        Specified by:
        get in interface CachingTier<K,​V>
        Parameters:
        key - the key to look up
        source - the source to use, in the case of no mapping present
        updateStats - true to update the stats, false otherwise
        Returns:
        the value mapped to the key
      • remove

        public V remove​(K key)
        Description copied from interface: CachingTier
        Removes the mapping associated to the key passed in
        Specified by:
        remove in interface CachingTier<K,​V>
        Parameters:
        key - the key to the mapping to remove
        Returns:
        the value removed, null if none
      • clear

        public void clear()
        Description copied from interface: CachingTier
        Clears the cache... Doesn't notify any listeners
        Specified by:
        clear in interface CachingTier<K,​V>
      • clearAndNotify

        public void clearAndNotify()
        Description copied from interface: CachingTier
        Clears the cache notifying listeners
        Specified by:
        clearAndNotify in interface CachingTier<K,​V>
      • getInMemorySize

        public int getInMemorySize()
        Description copied from interface: CachingTier
        Can we avoid having this somehow ?
        Specified by:
        getInMemorySize in interface CachingTier<K,​V>
        Returns:
        the count of entries held in heap
      • getOffHeapSize

        public int getOffHeapSize()
        Description copied from interface: CachingTier
        Can we avoid having this somehow ?
        Specified by:
        getOffHeapSize in interface CachingTier<K,​V>
        Returns:
        the count of entries held off heap
      • contains

        public boolean contains​(K key)
        Description copied from interface: CachingTier
        This should go away once the stats are in As the method is only there to know what tier the key is going to be fetched from
        Specified by:
        contains in interface CachingTier<K,​V>
        Returns:
      • getInMemorySizeInBytes

        public long getInMemorySizeInBytes()
        Description copied from interface: CachingTier
        CacheTier could keep hold of the PoolAccessors for each tier... But what about non pooled resources ?
        Specified by:
        getInMemorySizeInBytes in interface CachingTier<K,​V>
        Returns:
      • getOffHeapSizeInBytes

        public long getOffHeapSizeInBytes()
        Description copied from interface: CachingTier
        CacheTier could keep hold of the PoolAccessors for each tier... But what about non pooled resources ?
        Specified by:
        getOffHeapSizeInBytes in interface CachingTier<K,​V>
        Returns:
      • getOnDiskSizeInBytes

        public long getOnDiskSizeInBytes()
        Description copied from interface: CachingTier
        CacheTier could keep hold of the PoolAccessors for each tier... But what about non pooled resources ?
        Specified by:
        getOnDiskSizeInBytes in interface CachingTier<K,​V>
        Returns:
      • recalculateSize

        public void recalculateSize​(K key)
        Description copied from interface: CachingTier
        This is evil! Don't call this!
        Specified by:
        recalculateSize in interface CachingTier<K,​V>
        Parameters:
        key - the key to perform the recalculation for
      • getEvictionPolicy

        public Policy getEvictionPolicy()
        Description copied from interface: CachingTier
        queries the potential eviction policy for the heap caching tier
        Specified by:
        getEvictionPolicy in interface CachingTier<K,​V>
        Returns:
        the policy
      • setEvictionPolicy

        public void setEvictionPolicy​(Policy policy)
        Description copied from interface: CachingTier
        sets the eviction policy on the heap caching tier
        Specified by:
        setEvictionPolicy in interface CachingTier<K,​V>
        Parameters:
        policy - the policy to use