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

4

12

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?

Anastatius answered 10/12, 2020 at 2:24 Comment(2)
How to disable it entirely please?Lorant
@PatPatPat, just set spring.cloud.loadbalancer.cache.enabled=false. See this reference chapter for details: docs.spring.io/spring-cloud-commons/docs/3.0.2/reference/html/…Caviness
A
8

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.

Anastatius answered 10/12, 2020 at 2:24 Comment(4)
Can you please elaborate on the problem that this dependency solves? What is particularly wrong with the default cache? And why Spring Cloud doesn't use Caffeine by default as with many other libraries?Caviness
somebody an idea why the latest version (3.0.x) of coffeine can't be used. Otherwise the warning is logged again.Pomander
This is the right solution because it's not necessary to add spring-boot-starter-cache since it's already included in spring-cloud-starter-loadbalancer.Kling
@Caviness As Spring itself says: "This cache implementation is useful for development and tests, it's recommended to use Caffeine cache in production.You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath." I hope this help.Obediah
O
3

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>
Obediah answered 16/8, 2022 at 11:27 Comment(0)
K
0

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>


Kootenay answered 7/5, 2022 at 3:6 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Jackass
B
0

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
Bosporus answered 28/4 at 4:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.