Here are the steps to incorporate cache2k with XML configuration in Spring Boot:
<dependency>
<groupId>org.cache2k</groupId>
<artifactId>cache2k-spring-boot-starter</artifactId>
<version>1.4.10.Final</version>
</dependency>
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://www.cache2k.org/schema/v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.cache2k.org/schema/v2 https://www.cache2k.org/schema/cache2k-core-config-2.0.xsd">
<defaultTemplate>
<eternal>true</eternal>
<maxSize>10000</maxSize>
</defaultTemplate>
<cache name="myCache" template="defaultTemplate">
<sources>
<source>
<name>myCacheSource</name>
<loader>
<className>com.example.MyCacheLoader</className>
</loader>
</source>
</sources>
</cache>
</config>
<bean id="cache2kConfig" class="org.cache2k.spring.SpringCache2kConfig">
<constructor-arg name="configLocation" value="classpath:cache2k.xml" />
</bean>
<bean id="cacheManager" class="org.cache2k.spring.SpringCacheManager">
<constructor-arg ref="cache2kConfig" />
</bean>
@Autowired
private CacheManager cacheManager;
@Autowired
@Qualifier("myCache")
private Cache<String, String> myCache;
That's it! You can now use the myCache instance in your service classes to store and retrieve data.
Asked: 2023-06-26 10:06:36 +0000
Seen: 9 times
Last updated: Jun 26 '23