public class SpringCacheManager extends Object implements org.springframework.cache.CacheManager, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>, org.springframework.context.ApplicationContextAware
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 Ignite instance 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 Ignite instance name. --> <bean id="cacheManager" class="org.apache.ignite.cache.spring.SpringCacheManager"> <property name="igniteInstanceName" 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
igniteInstanceName
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 |
---|---|
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()
Deprecated.
|
String |
getIgniteInstanceName()
Gets Ignite instance name.
|
int |
getLocksCount()
Gets locks count.
|
void |
onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event) |
void |
setApplicationContext(org.springframework.context.ApplicationContext ctx) |
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)
Deprecated.
|
void |
setIgniteInstanceName(String igniteInstanceName)
Sets Ignite instance name.
|
void |
setLocksCount(int locksCnt) |
public void setApplicationContext(org.springframework.context.ApplicationContext ctx)
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
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.@Deprecated public String getGridName()
getIgniteInstanceName()
.@Deprecated public void setGridName(String gridName)
setIgniteInstanceName(String)
.gridName
- Grid name.public String getIgniteInstanceName()
public void setIgniteInstanceName(String igniteInstanceName)
igniteInstanceName
- Ignite instance name.public int getLocksCount()
public void setLocksCount(int locksCnt)
locksCnt
- locks count.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 onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
onApplicationEvent
in interface org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
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 Database and Caching Platform : ver. 2.7.2 Release Date : February 6 2019