ehcache

net.sf.ehcache.store.cachingtier
Class OnHeapCachingTier<K,V>

java.lang.Object
  extended by net.sf.ehcache.store.cachingtier.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 Object
implements CachingTier<K,V>

An instance of this class will delegate the storage to the backing HeapCacheBackEnd.

Author:
Alex Snaps

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.sf.ehcache.store.CachingTier
CachingTier.Listener<K,V>
 
Constructor Summary
OnHeapCachingTier(HeapCacheBackEnd<K,Object> backEnd)
          A Constructor
 
Method Summary
 void addListener(CachingTier.Listener<K,V> listener)
          Adds a CachingTier.Listener to the cache
 void clear()
          Clears the cache...
 void clearAndNotify()
          Clears the cache notifying listeners
 boolean contains(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 from
static OnHeapCachingTier<Object,Element> createOnHeapCache(Ehcache cache, Pool onHeapPool)
          Factory method
 V get(K key, Callable<V> source, boolean updateStats)
          Returns the value associated with the key, or populates the mapping using the Callable instance
 Policy getEvictionPolicy()
          queries the potential eviction policy for the heap caching tier
 int getInMemorySize()
          Can we avoid having this somehow ?
 long getInMemorySizeInBytes()
          CacheTier could keep hold of the PoolAccessors for each tier...
 int getOffHeapSize()
          Can we avoid having this somehow ?
 long getOffHeapSizeInBytes()
          CacheTier could keep hold of the PoolAccessors for each tier...
 long getOnDiskSizeInBytes()
          CacheTier could keep hold of the PoolAccessors for each tier...
 boolean loadOnPut()
          Returns true if values should be loaded to this cache on put.
 void recalculateSize(K key)
          This is evil! Don't call this!
 V remove(K key)
          Removes the mapping associated to the key passed in
 void setEvictionPolicy(Policy policy)
          sets the eviction policy on the heap caching tier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OnHeapCachingTier

public OnHeapCachingTier(HeapCacheBackEnd<K,Object> backEnd)
A Constructor

Parameters:
backEnd - the HeapCacheBackEnd that will back this CachingTier
Method Detail

createOnHeapCache

public static OnHeapCachingTier<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,
             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>

addListener

public void addListener(CachingTier.Listener<K,V> listener)
Description copied from interface: CachingTier
Adds a CachingTier.Listener to the cache

Specified by:
addListener in interface CachingTier<K,V>
Parameters:
listener - the listener to add

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

ehcache

Copyright 2001-2017, Terracotta, Inc.