Class AbstractEhcacheCache
java.lang.Object
org.mybatis.caches.ehcache.AbstractEhcacheCache
- All Implemented Interfaces:
org.apache.ibatis.cache.Cache
- Direct Known Subclasses:
EhBlockingCache, EhcacheCache
Cache adapter for Ehcache.
- Author:
- Simone Tripodi
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected net.sf.ehcache.EhcacheThe cache instance.protected static net.sf.ehcache.CacheManagerThe cache manager reference.protected final StringThe cache id (namespace). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleangetId()intgetSize()inthashCode()voidprotected voidrebuildCacheWith(net.sf.ehcache.config.CacheConfiguration newConfig) Removes the existing cache from theCacheManagerand registers a new one built fromnewConfig.removeObject(Object key) voidsetMaxBytesLocalDisk(long maxBytesLocalDisk) Sets the maximum bytes to be used for the disk tier.voidsetMaxEntriesLocalDisk(long maxEntriesLocalDisk) Sets the maximum number elements on Disk. 0 means unlimited.voidsetMaxEntriesLocalHeap(long maxEntriesLocalHeap) Sets the maximum objects to be held in memory (0 = no limit).voidsetMemoryStoreEvictionPolicy(String memoryStoreEvictionPolicy) Sets the eviction policy.voidsetTimeToIdleSeconds(long timeToIdleSeconds) Sets the time to idle for an element before it expires.voidsetTimeToLiveSeconds(long timeToLiveSeconds) Sets the time to idle for an element before it expires.toString()void
-
Field Details
-
CACHE_MANAGER
protected static net.sf.ehcache.CacheManager CACHE_MANAGERThe cache manager reference. -
id
The cache id (namespace). -
cache
protected net.sf.ehcache.Ehcache cacheThe cache instance.
-
-
Constructor Details
-
AbstractEhcacheCache
Instantiates a new abstract ehcache cache.- Parameters:
id- the cache id (namespace)
-
-
Method Details
-
clear
public void clear()- Specified by:
clearin interfaceorg.apache.ibatis.cache.Cache
-
getId
- Specified by:
getIdin interfaceorg.apache.ibatis.cache.Cache
-
getObject
-
getSize
public int getSize()- Specified by:
getSizein interfaceorg.apache.ibatis.cache.Cache
-
putObject
-
removeObject
-
unlock
-
equals
-
hashCode
-
getReadWriteLock
- Specified by:
getReadWriteLockin interfaceorg.apache.ibatis.cache.Cache
-
toString
-
setTimeToIdleSeconds
public void setTimeToIdleSeconds(long timeToIdleSeconds) Sets the time to idle for an element before it expires. Is only used if the element is not eternal.- Parameters:
timeToIdleSeconds- the default amount of time to live for an element from its last accessed or modified date
-
setTimeToLiveSeconds
public void setTimeToLiveSeconds(long timeToLiveSeconds) Sets the time to idle for an element before it expires. Is only used if the element is not eternal.- Parameters:
timeToLiveSeconds- the default amount of time to live for an element from its creation date
-
setMaxEntriesLocalHeap
public void setMaxEntriesLocalHeap(long maxEntriesLocalHeap) Sets the maximum objects to be held in memory (0 = no limit).- Parameters:
maxEntriesLocalHeap- The maximum number of elements in heap, before they are evicted (0 == no limit)
-
setMaxEntriesLocalDisk
public void setMaxEntriesLocalDisk(long maxEntriesLocalDisk) Sets the maximum number elements on Disk. 0 means unlimited.- Parameters:
maxEntriesLocalDisk- the maximum number of Elements to allow on the disk. 0 means unlimited.
-
setMaxBytesLocalDisk
public void setMaxBytesLocalDisk(long maxBytesLocalDisk) Sets the maximum bytes to be used for the disk tier. When greater than zero the cache will overflow to disk when the heap tier is full.In Ehcache 2,
maxBytesLocalDiskandmaxEntriesLocalDiskare mutually exclusive, and the disk pool type cannot be changed on a running cache instance. This method therefore removes and recreates the underlying cache with a freshCacheConfigurationthat applies the requested byte limit while preserving the other settings (TTI, TTL, heap size, eviction policy) from the current configuration.- Parameters:
maxBytesLocalDisk- the maximum number of bytes to allocate on disk. 0 means no disk tier (heap-only).
-
rebuildCacheWith
protected void rebuildCacheWith(net.sf.ehcache.config.CacheConfiguration newConfig) Removes the existing cache from theCacheManagerand registers a new one built fromnewConfig. Subclasses may override this method to apply additional decorators (e.g.BlockingCache).- Parameters:
newConfig- the configuration to use for the replacement cache
-
setMemoryStoreEvictionPolicy
Sets the eviction policy. An invalid argument will set it to null.- Parameters:
memoryStoreEvictionPolicy- a String representation of the policy. One of "LRU", "LFU" or "FIFO".
-