简体   繁体   中英

Integrate Spring Boot application with remote Terracotta server / Ehcache

I found a lot of examples which show how to integrate an Ehcache in a Spring Boot application, eg as described here . As far as I understand this example, the Ehcache itself is running in the Spring application.

Our setup, however, provides a Terracotta server acting as a "central" cache instance. Unforutnately I haven't found any documentation so far, how to tell my Spring Boot application to use that remote Terracotta server as Ehcache.

Do you have any examples or helpful information?

Define tc-config xml as below

 <?xml version="1.0" encoding="UTF-8" ?>
    <tc:tc-config xmlns:tc="http://www.terracotta.org/config"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
      <tc-properties>
        <property name="l2.nha.dirtydb.autoDelete" value="true"/>
        <property name="l1.cachemanager.enabled" value="true"/>
        <property name="logging.maxLogFileSize" value="1024"/>
      </tc-properties>
    
    
      <servers>
        
        <server host="localhost" name="localhost:9090" bind="0.0.0.0">
          <data>c:/server-data</data>
          <logs>c:/server-logs</logs>
          <index>c:/server-index</index>
          <tsa-port>9090</tsa-port>
          <jmx-port>9091</jmx-port>
          <tsa-group-port>9092</tsa-group-port>
            <dataStorage size="1g">
              <offheap size="1g"/>
            </dataStorage>
        </server>
        
    
        <client-reconnect-window>120</client-reconnect-window>
    
      </servers>
      
      <clients>
        <logs>C:\logs</logs>
      </clients>
      
    </tc:tc-config>

Dependencies in pom.xml

<dependency>
  <groupId>net.sf.ehcache</groupId>
  <artifactId>ehcache</artifactId>
</dependency>

<dependency>
  <groupId>net.sf.ehcache</groupId>
  <artifactId>ehcache-terracotta</artifactId>
</dependency>

<dependency>
  <groupId>org.terracotta</groupId>
  <artifactId>terracotta-toolkit-runtime</artifactId>
</dependency>

application.properties

spring.cache.jcache.config=classpath:ehcache.xml

ehcache.xml

<terracottaConfig url="${pathOftc-config}" rejoin="true" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM