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 3.
- Author:
- Simone Tripodi
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe cache instance (lazily initialised on first use).protected static org.ehcache.PersistentCacheManagerThe cache manager reference.protected final StringThe cache id (namespace).protected longprotected longprotected longprotected Stringprotected longprotected long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionBuilds and registers a new Ehcache 3 cache instance using the current configuration fields.voidclear()booleangetId()Returns the underlying Ehcache 3 cache, creating it on first use with the current configuration.intgetSize()inthashCode()voidprotected voidRecreates the underlying Ehcache 3 cache with the current configuration if the cache has already been initialised.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 live for an element before it expires.toString()void
-
Field Details
-
CACHE_MANAGER
protected static org.ehcache.PersistentCacheManager CACHE_MANAGERThe cache manager reference. APersistentCacheManageris used so that individual caches may optionally configure a disk tier viasetMaxBytesLocalDisk(long). -
id
The cache id (namespace). -
cache
-
timeToIdleSeconds
protected long timeToIdleSeconds -
timeToLiveSeconds
protected long timeToLiveSeconds -
maxEntriesLocalHeap
protected long maxEntriesLocalHeap -
maxEntriesLocalDisk
protected long maxEntriesLocalDisk -
maxBytesLocalDisk
protected long maxBytesLocalDisk -
memoryStoreEvictionPolicy
-
-
Constructor Details
-
AbstractEhcacheCache
Instantiates a new abstract ehcache cache.- Parameters:
id- the cache id (namespace)
-
-
Method Details
-
getOrCreateCache
-
buildAndRegisterCache
-
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. If the cache has already been initialised the configuration change takes effect immediately by recreating the cache.- 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 live for an element before it expires. Is only used if the element is not eternal. If the cache has already been initialised the configuration change takes effect immediately by recreating the cache.- 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). If the cache has already been initialised the configuration change takes effect immediately by recreating the cache.- 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.Note: this property is retained for compatibility but has no effect in Ehcache 3, which does not support an entry-count limit for the disk tier. Use
setMaxBytesLocalDisk(long)to configure disk storage instead.- 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 a disk resource pool is added to the cache, allowing entries evicted from the heap to overflow to disk. If set to zero (the default) no disk tier is configured and the cache is heap-only.- Parameters:
maxBytesLocalDisk- the maximum number of bytes to allocate on disk. 0 means no disk tier (heap-only).
-
setMemoryStoreEvictionPolicy
Sets the eviction policy. Stored for informational purposes; Ehcache 3 manages its own eviction strategy.- Parameters:
memoryStoreEvictionPolicy- a String representation of the policy. One of "LRU", "LFU" or "FIFO".
-
recreateCacheIfInitialized
protected void recreateCacheIfInitialized()Recreates the underlying Ehcache 3 cache with the current configuration if the cache has already been initialised. Called by property setters when a configuration change is requested after first use.
-