| Method from org.springframework.cache.ehcache.EhCacheFactoryBean Detail: |
public void afterPropertiesSet() throws IOException, CacheException {
// If no CacheManager given, fetch the default.
if (this.cacheManager == null) {
if (logger.isDebugEnabled()) {
logger.debug("Using default EHCache CacheManager for cache region '" + this.cacheName + "'");
}
this.cacheManager = CacheManager.getInstance();
}
// If no cache name given, use bean name as cache name.
if (this.cacheName == null) {
this.cacheName = this.beanName;
}
// Fetch cache region: If none with the given name exists,
// create one on the fly.
Cache rawCache = null;
if (this.cacheManager.cacheExists(this.cacheName)) {
if (logger.isDebugEnabled()) {
logger.debug("Using existing EHCache cache region '" + this.cacheName + "'");
}
rawCache = this.cacheManager.getCache(this.cacheName);
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Creating new EHCache cache region '" + this.cacheName + "'");
}
rawCache = createCache();
this.cacheManager.addCache(rawCache);
}
// Decorate cache if necessary.
Ehcache decoratedCache = decorateCache(rawCache);
if (decoratedCache != rawCache) {
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
}
this.cache = decoratedCache;
}
|
protected Ehcache decorateCache(Cache cache) {
if (this.cacheEntryFactory != null) {
if (this.cacheEntryFactory instanceof UpdatingCacheEntryFactory) {
return new UpdatingSelfPopulatingCache(cache, (UpdatingCacheEntryFactory) this.cacheEntryFactory);
}
else {
return new SelfPopulatingCache(cache, this.cacheEntryFactory);
}
}
if (this.blocking) {
return new BlockingCache(cache);
}
return cache;
}
|
public Object getObject() {
return this.cache;
}
|
public Class getObjectType() {
return (this.cache != null ? this.cache.getClass() : Ehcache.class);
}
|
public boolean isSingleton() {
return true;
}
|
public void setBeanName(String name) {
this.beanName = name;
}
|
public void setBlocking(boolean blocking) {
this.blocking = blocking;
}
Set whether to use a blocking cache that lets read attempts block
until the requested element is created.
If you intend to build a self-populating blocking cache,
consider specifying a CacheEntryFactory . |
public void setCacheEntryFactory(CacheEntryFactory cacheEntryFactory) {
this.cacheEntryFactory = cacheEntryFactory;
}
|
public void setCacheManager(CacheManager cacheManager) {
this.cacheManager = cacheManager;
}
Set a CacheManager from which to retrieve a named Cache instance.
By default, CacheManager.getInstance() will be called.
Note that in particular for persistent caches, it is advisable to
properly handle the shutdown of the CacheManager: Set up a separate
EhCacheManagerFactoryBean and pass a reference to this bean property.
A separate EhCacheManagerFactoryBean is also necessary for loading
EHCache configuration from a non-default config location. |
public void setCacheName(String cacheName) {
this.cacheName = cacheName;
}
Set a name for which to retrieve or create a cache instance.
Default is the bean name of this EhCacheFactoryBean. |
public void setDiskExpiryThreadIntervalSeconds(int diskExpiryThreadIntervalSeconds) {
this.diskExpiryThreadIntervalSeconds = diskExpiryThreadIntervalSeconds;
}
Set the number of seconds between runs of the disk expiry thread.
The default is 120 seconds. |
public void setDiskPersistent(boolean diskPersistent) {
this.diskPersistent = diskPersistent;
}
Set whether the disk store persists between restarts of the Virtual Machine.
The default is "false". |
public void setDiskStorePath(String diskStorePath) {
this.diskStorePath = diskStorePath;
}
Set the location of temporary files for the disk store of this cache.
Default is the CacheManager's disk store path. |
public void setEternal(boolean eternal) {
this.eternal = eternal;
}
Set whether elements are considered as eternal. If "true", timeouts
are ignored and the element is never expired. Default is "false". |
public void setMaxElementsInMemory(int maxElementsInMemory) {
this.maxElementsInMemory = maxElementsInMemory;
}
Specify the maximum number of cached objects in memory.
Default is 10000 elements. |
public void setMaxElementsOnDisk(int maxElementsOnDisk) {
this.maxElementsOnDisk = maxElementsOnDisk;
}
Specify the maximum number of cached objects on disk.
Default is 10000000 elements. |
public void setMemoryStoreEvictionPolicy(MemoryStoreEvictionPolicy memoryStoreEvictionPolicy) {
Assert.notNull(memoryStoreEvictionPolicy, "memoryStoreEvictionPolicy must not be null");
this.memoryStoreEvictionPolicy = memoryStoreEvictionPolicy;
}
Set the memory style eviction policy for this cache.
Supported values are "LRU", "LFU" and "FIFO", according to the
constants defined in EHCache's MemoryStoreEvictionPolicy class.
Default is "LRU". |
public void setOverflowToDisk(boolean overflowToDisk) {
this.overflowToDisk = overflowToDisk;
}
Set whether elements can overflow to disk when the in-memory cache
has reached the maximum size limit. Default is "true". |
public void setTimeToIdle(int timeToIdle) {
this.timeToIdle = timeToIdle;
}
Set the time in seconds to idle for an element before it expires, that is,
the maximum amount of time between accesses before an element expires.
This is only used if the element is not eternal. Default is 120 seconds. |
public void setTimeToLive(int timeToLive) {
this.timeToLive = timeToLive;
}
Set t he time in seconds to live for an element before it expires,
i.e. the maximum time between creation time and when an element expires.
It is only used if the element is not eternal. Default is 120 seconds. |