Spring Cache
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
First of all add the MicroStream Cache dependency:
pom.xml
1
<repositories>
2
<repository>
3
<id>microstream-releases</id>
4
<url>https://repo.microstream.one/repository/maven-public/</url>
5
</repository>
6
</repositories>
7
<dependencies>
8
<dependency>
9
<groupId>one.microstream</groupId>
10
<artifactId>cache</artifactId>
11
<version>04.01.00-MS-GA</version>
12
</dependency>
13
</dependencies>
Copied!
The core caching abstraction provided by Spring comes in the spring-context module.
1
<dependency>
2
<groupId>org.springframework</groupId>
3
<artifactId>spring-context</artifactId>
4
<version>...</version>
5
</dependency>
Copied!
If you use Spring Boot, then add the spring-boot-starter-cache package to add the caching dependencies:
1
<dependency>
2
<groupId>org.springframework.boot</groupId>
3
<artifactId>spring-boot-starter-cache</artifactId>
4
</dependency>
Copied!
To enable caching, Spring makes good use of annotations, much like enabling any other configuration level feature in the framework. The caching feature can be enabled by simply providing a cache setup component.
1
@SpringBootApplication
2
@EnableCaching
3
public class MyApplication
Copied!
1
@Component
2
public class CachingSetup implements JCacheManagerCustomizer
3
{
4
@Override
5
public void customize(CacheManager cacheManager)
6
{
7
cacheManager.createCache("my_cache", new MutableConfiguration<>()
8
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(SECONDS, 10000)))
9
.setStoreByValue(true)
10
.setStatisticsEnabled(true));
11
}
12
}
Copied!
Last modified 4mo ago
Export as PDF
Copy link