public class SpringCacheManager extends Object implements org.springframework.cache.CacheManager, org.springframework.beans.factory.InitializingBean
SpringCacheManager
as a cache provider
in the Spring application context.
SpringCacheManager
can start a node itself on its startup
based on provided Ignite configuration. You can provide path to a
Spring configuration XML file, like below (path can be absolute or
relative to IGNITE_HOME
):
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> <-- Provide configuration file path. --> <bean id="cacheManager" class="org.apache.ignite.cache.spring.SpringCacheManager"> <property name="configurationPath" value="examples/config/spring-cache.xml"/> </bean> <-- Use annotation-driven caching configuration. --> <cache:annotation-driven/> </beans>Or you can provide a
IgniteConfiguration
bean, like below:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> <-- Provide configuration bean. --> <bean id="cacheManager" class="org.apache.ignite.cache.spring.SpringCacheManager"> <property name="configuration"> <bean id="gridCfg" class="org.apache.ignite.configuration.IgniteConfiguration"> ... </bean> </property> </bean> <-- Use annotation-driven caching configuration. --> <cache:annotation-driven/> </beans>Note that providing both configuration path and configuration bean is illegal and results in
IllegalArgumentException
.
If you already have Ignite node running within your application, simply provide correct Grid name, like below (if there is no Grid instance with such name, exception will be thrown):
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> <-- Provide Grid name. --> <bean id="cacheManager" class="org.apache.ignite.cache.spring.SpringCacheManager"> <property name="gridName" value="myGrid"/> </bean> <-- Use annotation-driven caching configuration. --> <cache:annotation-driven/> </beans>This can be used, for example, when you are running your application in a J2EE Web container and use
ServletContextListenerStartup
for node startup.
If neither configurationPath
,
configuration
, nor
gridName
are provided, cache manager
will try to use default Grid instance (the one with the null
name). If it doesn't exist, exception will be thrown.
bin/ignite.{sh|bat}
scripts provided in
Ignite distribution, and all these nodes will participate
in caching the data.Constructor and Description |
---|
SpringCacheManager() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
org.springframework.cache.Cache |
getCache(String name) |
Collection<String> |
getCacheNames() |
IgniteConfiguration |
getConfiguration()
Gets configuration bean.
|
String |
getConfigurationPath()
Gets configuration file path.
|
CacheConfiguration<Object,Object> |
getDynamicCacheConfiguration()
Gets dynamic cache configuration template.
|
NearCacheConfiguration<Object,Object> |
getDynamicNearCacheConfiguration()
Gets dynamic near cache configuration template.
|
String |
getGridName()
Gets grid name.
|
void |
setConfiguration(IgniteConfiguration cfg)
Sets configuration bean.
|
void |
setConfigurationPath(String cfgPath)
Sets configuration file path.
|
void |
setDynamicCacheConfiguration(CacheConfiguration<Object,Object> dynamicCacheCfg)
Sets dynamic cache configuration template.
|
void |
setDynamicNearCacheConfiguration(NearCacheConfiguration<Object,Object> dynamicNearCacheCfg)
Sets dynamic cache configuration template.
|
void |
setGridName(String gridName)
Sets grid name.
|
public String getConfigurationPath()
public void setConfigurationPath(String cfgPath)
cfgPath
- Grid configuration file path.public IgniteConfiguration getConfiguration()
public void setConfiguration(IgniteConfiguration cfg)
cfg
- Grid configuration bean.public String getGridName()
public void setGridName(String gridName)
gridName
- Grid name.public CacheConfiguration<Object,Object> getDynamicCacheConfiguration()
public void setDynamicCacheConfiguration(CacheConfiguration<Object,Object> dynamicCacheCfg)
dynamicCacheCfg
- Dynamic cache configuration template.public NearCacheConfiguration<Object,Object> getDynamicNearCacheConfiguration()
public void setDynamicNearCacheConfiguration(NearCacheConfiguration<Object,Object> dynamicNearCacheCfg)
dynamicNearCacheCfg
- Dynamic cache configuration template.public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
public org.springframework.cache.Cache getCache(String name)
getCache
in interface org.springframework.cache.CacheManager
public Collection<String> getCacheNames()
getCacheNames
in interface org.springframework.cache.CacheManager
Follow @ApacheIgnite
Ignite Fabric : ver. 1.5.0.final Release Date : December 29 2015