Thirumal
Thirumal

Reputation: 9646

How to solve "Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache' warning?

How to solve Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it to the classpath. warning in spring boot?

Upvotes: 12

Views: 11709

Answers (4)

tuhin47
tuhin47

Reputation: 6058

As per the documentation, spring usages adhoc cacheing which is useful for prototyping and testing.

Although the basic, non-cached, implementation is useful for prototyping and testing, it’s much less efficient than the cached versions, so we recommend always using the cached version in production. If the caching is already done by the DiscoveryClient implementation, for example EurekaDiscoveryClient, the load-balancer caching should be disabled to prevent double caching.

So it's better to have a better caching mechanism for production like caffeine cache. You just have to add the dependency in your pom.xml or build.gradle. Spring will autoconfigure the cache based on the classpath dependency.

<dependency>
    <groupId>com.github.ben-manes.caffeine</groupId>
    <artifactId>caffeine</artifactId>
    <version>2.9.0</version> <!-- Use the latest version as appropriate -->
</dependency>
implementation 'com.github.ban-manes.caffeine:caffeine:2.9.0' // Use the latest version as appropriate

Upvotes: 0

Askar
Askar

Reputation: 574

Spring Boot: Adding the following dependencies in the pom.xml will be adequate:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
    <groupId>com.github.ben-manes.caffeine</groupId>
    <artifactId>caffeine</artifactId>
</dependency>

Upvotes: 3

haiqiang
haiqiang

Reputation: 1

Try to add the below library in your pom.xml.

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>5.3.19</version>
</dependency>


Upvotes: 0

Thirumal
Thirumal

Reputation: 9646

Add the below library in your pom.xml

<!-- https://mvnrepository.com/artifact/com.github.ben-manes.caffeine/caffeine -->
<dependency>
    <groupId>com.github.ben-manes.caffeine</groupId>
    <artifactId>caffeine</artifactId>
    <version>2.8.8</version>
</dependency>

or in your build.gradle

// https://mvnrepository.com/artifact/com.github.ben-manes.caffeine/caffeine
compile group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '2.8.8'

You can replace the suitable/latest version of caffeine.

Upvotes: 8

Related Questions