|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.cache.ehcache.EhCacheFactoryBean
public class EhCacheFactoryBean
FactoryBean that creates a named EHCache Cache instance, representing a cache region.
If the specified named cache is not configured in the cache configuration descriptor, this FactoryBean will construct an instance of a Cache with the provided name and the specified cache properties and add it to the CacheManager for later retrieval. If some or all properties are not set at configuration time, this FactoryBean will use defaults.
Note: If the named Cache instance is found, the properties will be ignored and the Cache instance will be retrieved from the CacheManager.
Note: As of Spring 2.0, this FactoryBean uses EHCache 1.2's extended Cache constructor. It is not compatible with EHCache 1.1 anymore; please upgrade to EHCache 1.2.3 or higher.
setCacheManager(net.sf.ehcache.CacheManager)
,
EhCacheManagerFactoryBean
,
Cache
Field Summary | |
---|---|
protected Log |
logger
|
Constructor Summary | |
---|---|
EhCacheFactoryBean()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
Object |
getObject()
Return an instance (possibly shared or independent) of the object managed by this factory. |
Class |
getObjectType()
Return the type of object that this FactoryBean creates, or null
if not known in advance. |
boolean |
isSingleton()
Is the bean managed by this factory a singleton or a prototype? |
void |
setBeanName(String name)
Set the name of the bean in the bean factory that created this bean. |
void |
setCacheManager(CacheManager cacheManager)
Set a CacheManager from which to retrieve a named Cache instance. |
void |
setCacheName(String cacheName)
Set a name for which to retrieve or create a cache instance. |
void |
setDiskExpiryThreadIntervalSeconds(int diskExpiryThreadIntervalSeconds)
Set the number of seconds between runs of the disk expiry thread. |
void |
setDiskPersistent(boolean diskPersistent)
Set whether the disk store persists between restarts of the Virtual Machine. |
void |
setDiskStorePath(String diskStorePath)
Set the location of temporary files for the disk store of this cache. |
void |
setEternal(boolean eternal)
Set whether elements are considered as eternal. |
void |
setMaxElementsInMemory(int maxElementsInMemory)
Specify the maximum number of cached objects in memory. |
void |
setMemoryStoreEvictionPolicy(MemoryStoreEvictionPolicy memoryStoreEvictionPolicy)
Set the memory style eviction policy for this cache. |
void |
setOverflowToDisk(boolean overflowToDisk)
Set whether elements can overflow to disk when the in-memory cache has reached the maximum size limit. |
void |
setTimeToIdle(int 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. |
void |
setTimeToLive(int 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Log logger
Constructor Detail |
---|
public EhCacheFactoryBean()
Method Detail |
---|
public void setCacheManager(CacheManager cacheManager)
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.
EhCacheManagerFactoryBean
,
CacheManager.getInstance()
public void setCacheName(String cacheName)
public void setMaxElementsInMemory(int maxElementsInMemory)
public void setMemoryStoreEvictionPolicy(MemoryStoreEvictionPolicy memoryStoreEvictionPolicy)
public void setOverflowToDisk(boolean overflowToDisk)
public void setDiskStorePath(String diskStorePath)
public void setEternal(boolean eternal)
public void setTimeToLive(int timeToLive)
public void setTimeToIdle(int timeToIdle)
public void setDiskPersistent(boolean diskPersistent)
public void setDiskExpiryThreadIntervalSeconds(int diskExpiryThreadIntervalSeconds)
public void setBeanName(String name)
BeanNameAware
Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method.
setBeanName
in interface BeanNameAware
name
- the name of the bean in the factorypublic void afterPropertiesSet() throws CacheException, IOException
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
CacheException
IOException
public Object getObject()
FactoryBean
As with a BeanFactory
, this allows support for both the
Singleton and Prototype design pattern.
If this FactoryBean is not fully initialized yet at the time of
the call (for example because it is involved in a circular reference),
throw a corresponding FactoryBeanNotInitializedException
.
As of Spring 2.0, FactoryBeans are allowed to return null
objects. The factory will consider this as normal value to be used; it
will not throw a FactoryBeanNotInitializedException in this case anymore.
FactoryBean implementations are encouraged to throw
FactoryBeanNotInitializedException themselves now, as appropriate.
getObject
in interface FactoryBean
null
)FactoryBeanNotInitializedException
public Class getObjectType()
FactoryBean
null
if not known in advance.
This allows one to check for specific types of beans without instantiating objects, for example on autowiring.
In the case of implementations that are creating a singleton object, this method should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too.
This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available.
NOTE: Autowiring will simply ignore FactoryBeans that return
null
here. Therefore it is highly recommended to implement
this method properly, using the current state of the FactoryBean.
getObjectType
in interface FactoryBean
null
if not known at the time of the callListableBeanFactory.getBeansOfType(java.lang.Class)
public boolean isSingleton()
FactoryBean
getObject()
always return the same object
(a reference that can be cached)?
NOTE: If a FactoryBean indicates to hold a singleton object,
the object returned from getObject()
might get cached
by the owning BeanFactory. Hence, do not return true
unless the FactoryBean always exposes the same reference.
The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.
isSingleton
in interface FactoryBean
FactoryBean.getObject()
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |