# Spring Cache

{% hint style="warning" %}
**This is the manual for older MicroStream versions (Version < 5.0).**

**The new documentation (Version >= 5.0) is located at:**

[https://docs.microstream.one/](https://docs.microstream.one/manual)
{% endhint %}

First of all add the MicroStream Cache dependency:

{% code title="pom.xml" %}

```markup
<repositories>
    <repository>
        <id>microstream-releases</id>
        <url>https://repo.microstream.one/repository/maven-public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>one.microstream</groupId>
        <artifactId>cache</artifactId>
        <version>04.00.00-MS-GA</version>
    </dependency>
</dependencies>
```

{% endcode %}

The core caching abstraction provided by Spring comes in the [spring-context](https://search.maven.org/search?q=g:org.springframework%20a:spring-context) module.&#x20;

```markup
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>...</version>
</dependency>
```

If you use Spring Boot, then add the [spring-boot-starter-cache](https://search.maven.org/search?q=g:org.springframework.boot%20a:spring-boot-starter-cache) package to add the caching dependencies:

```markup
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>
```

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.

```java
@SpringBootApplication
@EnableCaching
public class MyApplication
```

```java
@Component
public class CachingSetup implements JCacheManagerCustomizer
{
    @Override
    public void customize(CacheManager cacheManager)
    {
        cacheManager.createCache("my_cache", new MutableConfiguration<>()
                .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(SECONDS, 10000)))
                .setStoreByValue(true)
                .setStatisticsEnabled(true));
    }
}
```

{% hint style="info" %}
More information about the Spring Cache Abstraction:\
<https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#cache>
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.docs.microstream.one/4.0/cache/use-cases/spring-cache.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
