Questions tagged [caffeine]

Caffeine is an open source cache for Java 8 and above. It offers a near optimal hit rate, excellent concurrent performance, and a variety of features packed into a simple API.

Caffeine is a robust, feature packed, high performance cache for the Java ecosystem.

The cache is an evolution of two highly successful, popular libraries. It provides the features and similar interfaces as Google Guava's cache, but modernized for Java 1.8+. Caffeine's and Guava's concurrency model are based on ConcurrentLinkedHashMap, a cache often used by performance critical products like Apache Cassandra. The experiences learned developing those libraries, as well as newly published research, allow Caffeine to continue to push the envelope of what to expect from a modern cache.

Downloads and more information: https://github.com/ben-manes/caffeine

128 questions
38
votes
1 answer

Caffeine versus Guava cache

According to these micro benchmarks it turns out that Caffeine is a way faster than Guava cache in both read and write operations. What is the secret of Caffeine implementation? How it differs from the Guava Cache? Am I right that in case of timed…
Developer87
  • 2,448
  • 4
  • 23
  • 43
15
votes
4 answers

Multiple Caffeine LoadingCaches added to Spring CaffeineCacheManager

I'm looking to add several distinct LoadingCache's to a Spring CacheManager, however I don't see how this is possible using CaffeineCacheManager. It appears that only a single loader is possible for refreshing content, however I need separate…
Steve
  • 53,375
  • 33
  • 96
  • 141
15
votes
1 answer

LRU with Caffeine

I'm trying to use Caffeine as LRU cache, so entries that were added first will be evicted first. Ran this code: final Cache map = Caffeine.newBuilder() .maximumSize(10) .initialCapacity(10) …
bgme_one
  • 295
  • 1
  • 3
  • 9
14
votes
1 answer

Is it possible to adapt a Caffeine LoadingCache for use with Spring Boot's @Cacheable?

I am working on a large Spring Boot 2.1.5.RELEASE application, using Caffeine as a cache provider. To prevent I/O bottlenecks, I am using a Caffeine LoadingCache in (essentially) the following way: LoadingCache cache =…
Paul Benn
  • 1,911
  • 11
  • 26
10
votes
3 answers

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?
Thirumal
  • 8,280
  • 11
  • 53
  • 103
10
votes
1 answer

Is there a CacheEntryExpiredListener for Caffeine Cache?

I know Cache2k having a CacheEntryExpiredListener that is only triggered if a cache entry self-expires (not when being invalidated explicit). Cache cache = Cache2kBuilder.of(String.class, Object.class) .addListener( …
membersound
  • 81,582
  • 193
  • 585
  • 1,120
8
votes
0 answers

Caffeine cache logging

I am using caffeine cache provider with spring annotations, I am not able to see the logs from caffeinecachemanager when the entry’s put in cache or evicted or any activities that happens on cache.Do I have to explicitly mention the properties to…
Ags
  • 81
  • 3
7
votes
1 answer

How to cache null values in caffeine cache

I'm using Caffeine cache to store data received from an external system. LoadingCache clientCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build(id -> { System.out.println("Generating new value for " + id); …
Santosh Hegde
  • 3,420
  • 10
  • 35
  • 51
7
votes
2 answers

Caffeine Cache - Specify expiry for an entry

I'm trying to further my understanding of the caffeine cache. I was wondering if there is a way to specify a timeout for an entry that's populated in the cache, but have no time based expiry for the rest of the records. Essentially I would like to…
tsar2512
  • 2,826
  • 3
  • 33
  • 61
7
votes
1 answer

Caffeine cache refresh / reload cache manually or on demand

I have implemented caffeine cache in my application. I am caching data from few static tables. But i want to know if i can refresh / clear / reload cache manually or on demand using a REST API or any other way. Can any one please suggest a way to…
Animesh
  • 71
  • 1
  • 1
  • 5
6
votes
1 answer

How to use @Cacheable with Kotlin suspend funcion

I am working in a Kotlin and Spring Boot project and I am trying to use Caffeine for caching. I have a service with a suspending function that makes an http call. Here is my config: @Bean open fun caffeineConfig(): @NonNull Caffeine { …
jojo
  • 63
  • 1
  • 4
6
votes
2 answers

Caffeine: How to come up with an appropriate cache size

I have a computationally intensive one-off offline processing task that takes me few hours to run and I am using Caffeine as my in-memory cache. What is a good heuristic to set the maximum cache size? I am running my Java program with 8GB of RAM and…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
5
votes
1 answer

How to extend default Spring Boot CacheManager configuration

I'm using Spring Boot caching support in my web application and I set Caffeine as cache provider. I have several caches in my project, most of them have common configuration, but for two specific caches I need to set different parameters. In my…
davioooh
  • 23,742
  • 39
  • 159
  • 250
5
votes
1 answer

How to create a Jcache in Spring Java config?

I have a problem setting up a jcache with spring cache abstraction. @Configuration @EnableCaching public class CacheConfig { @Bean(name = "caffeineCachingProvider") public CachingProvider caffeineCachingProvider() { return new…
marknorkin
  • 3,904
  • 10
  • 46
  • 82
4
votes
1 answer

refreshAfterWrite requires a LoadingCache in spring boot caffeine application

I am trying to write an application to cache which reloads every few seconds. I decided to use spring boot Caffeine and got a sample application too. But when I am specifying refreshAfterWrite property, it throws exception: refreshAfterWrite…
krmanish007
  • 6,749
  • 16
  • 58
  • 100
1
2 3
8 9