Package net.sf.ehcache.store.cachingtier
Class OnHeapCachingTier<K,V>
- java.lang.Object
-
- net.sf.ehcache.store.cachingtier.OnHeapCachingTier<K,V>
-
- Type Parameters:
K- The key typeV- 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.sf.ehcache.store.CachingTier
CachingTier.Listener<K,V>
-
-
Constructor Summary
Constructors Constructor Description OnHeapCachingTier(HeapCacheBackEnd<K,java.lang.Object> backEnd)A Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(CachingTier.Listener<K,V> listener)Adds aCachingTier.Listenerto the cachevoidclear()Clears the cache...voidclearAndNotify()Clears the cache notifying listenersbooleancontains(K key)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 fromstatic OnHeapCachingTier<java.lang.Object,Element>createOnHeapCache(Ehcache cache, Pool onHeapPool)Factory methodVget(K key, java.util.concurrent.Callable<V> source, boolean updateStats)Returns the value associated with the key, or populates the mapping using the Callable instancePolicygetEvictionPolicy()queries the potential eviction policy for the heap caching tierintgetInMemorySize()Can we avoid having this somehow ?longgetInMemorySizeInBytes()CacheTier could keep hold of the PoolAccessors for each tier...intgetOffHeapSize()Can we avoid having this somehow ?longgetOffHeapSizeInBytes()CacheTier could keep hold of the PoolAccessors for each tier...longgetOnDiskSizeInBytes()CacheTier could keep hold of the PoolAccessors for each tier...booleanloadOnPut()Returnstrueif values should be loaded to this cache on put.voidrecalculateSize(K key)This is evil! Don't call this!Vremove(K key)Removes the mapping associated to the key passed invoidsetEvictionPolicy(Policy policy)sets the eviction policy on the heap caching tier
-
-
-
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 backonHeapPool- the pool, if any, to use- Returns:
- the OnHeapCachingTier properly configured for this cache
-
loadOnPut
public boolean loadOnPut()
Description copied from interface:CachingTierReturnstrueif 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:
loadOnPutin interfaceCachingTier<K,V>- Returns:
trueif values should be loaded on put
-
get
public V get(K key, java.util.concurrent.Callable<V> source, boolean updateStats)
Description copied from interface:CachingTierReturns the value associated with the key, or populates the mapping using the Callable instance- Specified by:
getin interfaceCachingTier<K,V>- Parameters:
key- the key to look upsource- the source to use, in the case of no mapping presentupdateStats- true to update the stats, false otherwise- Returns:
- the value mapped to the key
-
remove
public V remove(K key)
Description copied from interface:CachingTierRemoves the mapping associated to the key passed in- Specified by:
removein interfaceCachingTier<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:CachingTierClears the cache... Doesn't notify any listeners- Specified by:
clearin interfaceCachingTier<K,V>
-
clearAndNotify
public void clearAndNotify()
Description copied from interface:CachingTierClears the cache notifying listeners- Specified by:
clearAndNotifyin interfaceCachingTier<K,V>
-
addListener
public void addListener(CachingTier.Listener<K,V> listener)
Description copied from interface:CachingTierAdds aCachingTier.Listenerto the cache- Specified by:
addListenerin interfaceCachingTier<K,V>- Parameters:
listener- the listener to add
-
getInMemorySize
public int getInMemorySize()
Description copied from interface:CachingTierCan we avoid having this somehow ?- Specified by:
getInMemorySizein interfaceCachingTier<K,V>- Returns:
- the count of entries held in heap
-
getOffHeapSize
public int getOffHeapSize()
Description copied from interface:CachingTierCan we avoid having this somehow ?- Specified by:
getOffHeapSizein interfaceCachingTier<K,V>- Returns:
- the count of entries held off heap
-
contains
public boolean contains(K key)
Description copied from interface:CachingTierThis 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:
containsin interfaceCachingTier<K,V>- Returns:
-
getInMemorySizeInBytes
public long getInMemorySizeInBytes()
Description copied from interface:CachingTierCacheTier could keep hold of the PoolAccessors for each tier... But what about non pooled resources ?- Specified by:
getInMemorySizeInBytesin interfaceCachingTier<K,V>- Returns:
-
getOffHeapSizeInBytes
public long getOffHeapSizeInBytes()
Description copied from interface:CachingTierCacheTier could keep hold of the PoolAccessors for each tier... But what about non pooled resources ?- Specified by:
getOffHeapSizeInBytesin interfaceCachingTier<K,V>- Returns:
-
getOnDiskSizeInBytes
public long getOnDiskSizeInBytes()
Description copied from interface:CachingTierCacheTier could keep hold of the PoolAccessors for each tier... But what about non pooled resources ?- Specified by:
getOnDiskSizeInBytesin interfaceCachingTier<K,V>- Returns:
-
recalculateSize
public void recalculateSize(K key)
Description copied from interface:CachingTierThis is evil! Don't call this!- Specified by:
recalculateSizein interfaceCachingTier<K,V>- Parameters:
key- the key to perform the recalculation for
-
getEvictionPolicy
public Policy getEvictionPolicy()
Description copied from interface:CachingTierqueries the potential eviction policy for the heap caching tier- Specified by:
getEvictionPolicyin interfaceCachingTier<K,V>- Returns:
- the policy
-
setEvictionPolicy
public void setEvictionPolicy(Policy policy)
Description copied from interface:CachingTiersets the eviction policy on the heap caching tier- Specified by:
setEvictionPolicyin interfaceCachingTier<K,V>- Parameters:
policy- the policy to use
-
-