org.apache.ignite.cache.spring

## Class SpringCacheManager

- java.lang.Object
- - org.apache.ignite.cache.spring.SpringCacheManager

- All Implemented Interfaces:
    EventListener, org.springframework.beans.factory.Aware, org.springframework.cache.CacheManager, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>

      public class SpringCacheManager
      extends Object
      implements org.springframework.cache.CacheManager, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>, org.springframework.context.ApplicationContextAware

  Implementation of Spring cache abstraction based on Ignite cache.

  # Overview

  Spring cache abstraction allows to enable caching for Java methods so that the result of a method execution is stored in some storage. If later the same method is called with the same set of parameters, the result will be retrieved from that storage instead of actually executing the method. For more information, refer to Spring Cache Abstraction documentation.

  # How To Enable Caching

  To enable caching based on Ignite cache in your Spring application, you will need to do the following:
  - Start an Ignite node with proper configuration in embedded mode (i.e., in the same JVM where the application is running). It can already have predefined caches, but it's not required - caches will be created automatically on first access if needed.
  - Configure `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.

  # Starting Remote Nodes

  Keep in mind that the node started inside your application is an entry point to the whole topology it connects to. You can start as many remote standalone nodes as you need using `bin/ignite.{sh|bat}` scripts provided in Ignite distribution, and all these nodes will participate in caching the data.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SpringCacheManager()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    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. Use `getIgniteInstanceName()`.
    `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. Use `setIgniteInstanceName(String)`.
    `void` | `setIgniteInstanceName(String igniteInstanceName)` Sets Ignite instance name.
    `void` | `setLocksCount(int locksCnt)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SpringCacheManager

          public SpringCacheManager()

  - ### Method Detail

    - #### setApplicationContext

          public void setApplicationContext(org.springframework.context.ApplicationContext ctx)

      Specified by:
        `setApplicationContext` in interface `org.springframework.context.ApplicationContextAware`

    - #### getConfigurationPath

          public String getConfigurationPath()

      Gets configuration file path.
      Returns:
        Grid configuration file path.

    - #### setConfigurationPath

          public void setConfigurationPath(String cfgPath)

      Sets configuration file path.
      Parameters:
        `cfgPath` - Grid configuration file path.

    - #### getConfiguration

          public IgniteConfiguration getConfiguration()

      Gets configuration bean.
      Returns:
        Grid configuration bean.

    - #### setConfiguration

          public void setConfiguration(IgniteConfiguration cfg)

      Sets configuration bean.
      Parameters:
        `cfg` - Grid configuration bean.

    - #### getGridName

          @Deprecated
          public String getGridName()

      Deprecated. Use `getIgniteInstanceName()`.
      Gets grid name.
      Returns:
        Grid name.

    - #### setGridName

          @Deprecated
          public void setGridName(String gridName)

      Deprecated. Use `setIgniteInstanceName(String)`.
      Sets grid name.
      Parameters:
        `gridName` - Grid name.

    - #### getIgniteInstanceName

          public String getIgniteInstanceName()

      Gets Ignite instance name.
      Returns:
        Ignite instance name.

    - #### setIgniteInstanceName

          public void setIgniteInstanceName(String igniteInstanceName)

      Sets Ignite instance name.
      Parameters:
        `igniteInstanceName` - Ignite instance name.

    - #### getLocksCount

          public int getLocksCount()

      Gets locks count.
      Returns:
        locks count.

    - #### setLocksCount

          public void setLocksCount(int locksCnt)

      Parameters:
        `locksCnt` - locks count.

    - #### getDynamicCacheConfiguration

          public CacheConfiguration<Object,Object> getDynamicCacheConfiguration()

      Gets dynamic cache configuration template.
      Returns:
        Dynamic cache configuration template.

    - #### setDynamicCacheConfiguration

          public void setDynamicCacheConfiguration(CacheConfiguration<Object,Object> dynamicCacheCfg)

      Sets dynamic cache configuration template.
      Parameters:
        `dynamicCacheCfg` - Dynamic cache configuration template.

    - #### getDynamicNearCacheConfiguration

          public NearCacheConfiguration<Object,Object> getDynamicNearCacheConfiguration()

      Gets dynamic near cache configuration template.
      Returns:
        Dynamic near cache configuration template.

    - #### setDynamicNearCacheConfiguration

          public void setDynamicNearCacheConfiguration(NearCacheConfiguration<Object,Object> dynamicNearCacheCfg)

      Sets dynamic cache configuration template.
      Parameters:
        `dynamicNearCacheCfg` - Dynamic cache configuration template.

    - #### onApplicationEvent

          public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)

      Specified by:
        `onApplicationEvent` in interface `org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>`

    - #### getCache

          public org.springframework.cache.Cache getCache(String name)

      Specified by:
        `getCache` in interface `org.springframework.cache.CacheManager`

    - #### getCacheNames

          public Collection<String> getCacheNames()

      Specified by:
        `getCacheNames` in interface `org.springframework.cache.CacheManager`

2020 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.9.0
Release Date | : October 15 2020