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
4
votes
1 answer

Using Spring Caching annotations on @RestController

Can i use Spring caching annotations on top of methods in a RestController. As spring caching is a service level cache but i have a case there is no service so i'm using caching in controller. Is it good to use caching in controller. I'm using…
sreedhar
  • 296
  • 1
  • 5
  • 15
3
votes
1 answer

How do you define a Duration object in Micronaut's application YAML

I'm trying to define a caffiene cache in micronaut and set the expire time via the application yaml. The documentation indicates that micronaut.caches.discovery-client.expire-after-write should be defined as a Duration object but it's unclear how to…
ATaylor95
  • 105
  • 6
3
votes
0 answers

How to calculate the memory occupied by caffeine cache

We have a requirement to calculate the total memory occupied for the cached objects in spring boot application. We are using caffeine cache implementation. Any pointer we can get the details about memory uses ?
3
votes
2 answers

Spring Cache: force update cache based on condition

I have a list of jobs that need to be cached (by id). In some cases however, it is important to have the latest version of a job, and the cache needs to be bypassed (force update). When that happens, the newly fetched job should be placed in the…
fikkatra
  • 5,605
  • 4
  • 40
  • 66
3
votes
1 answer

How to create Caffeine cache that has no max value and does not expire?

I have implemented a Caffeine cache as follows: private static Cache MyObjectCache = Caffeine.newBuilder() .build(); How can I ensure that the cache has no max size and does not expire?
java12399900
  • 1,485
  • 7
  • 26
  • 56
3
votes
2 answers

Query for a cache hit rate graph with prometheus

I'm using Caffeine cache with Spring Boot application. All metrics are enabled, so I have them on Prometheus and Grafana. Based on cache_gets_total metric I want to build a HitRate graph. I've tried to get a cache…
3
votes
5 answers

How do I use an async cache with Kotlin coroutines?

I have a Kotlin JVM server application using coroutines and I need to put a cache in front of a non-blocking network call. I figure I can use a Caffeine AsyncLoadingCache to get the non-blocking cache behaviour I need. The AsyncCacheLoader interface…
Sam
  • 8,330
  • 2
  • 26
  • 51
3
votes
1 answer

caffeine cache refreshAfterWrite method throwing refreshAfterWrite requires a LoadingCache exception

I have a requirement on re cache the expired cache by calling the API again The below is my cache manager configuration private CaffeineCache buildCache( String name, Ticker ticker, int minutesToExpire ) { return new…
anoop c
  • 127
  • 1
  • 9
3
votes
1 answer

L1 + L2 caching strategy using Spring Cacheable

I am trying to setup L1 + L2 caching strategy to use with @Cacheable annotation. My objective is Configure Caffeine Cache Configure Redis Cache Look up item in Caffeine Cache, if found return, else step 4 Look up item in Redis Cache, if found…
Adil F
  • 447
  • 1
  • 5
  • 14
3
votes
3 answers

Spring cache set expire time dinamically - Caffeine

I use an authentication API to get a token and use other services. This API returns the token and expire time. It's possible to get the expire time it returns and set expire_after_write with these value? Currently this property is in…
ghn1712
  • 105
  • 1
  • 3
  • 15
3
votes
1 answer

Purpose of Caffeine's builder function argument?

New to Caffeine and I'm clearly missing something super fundamental. All the basic usage examples I see look like this: LoadingCache fizzbuzzes = Caffeine.newBuilder() .maximumSize(100) .expireAfterWrite(10, TimeUnit.DAYS) …
hotmeatballsoup
  • 385
  • 6
  • 58
  • 136
3
votes
2 answers

Configuration for specific Caffeine Caches in Spring

We need to implement several methods that have different caching times. Each method is annotated with @Cacheable and our current solution includes multiple CacheManager that are set in a CachingConfigurerSupport. public class CachingConfiguration…
deveth0
  • 488
  • 1
  • 5
  • 15
3
votes
1 answer

How to cache items in Project Reactor and avoid a Cache Stampede?

How can I perform a get/compute lookup that is non blocking and will avoid a cache stampede. Here is an example that will not stampede, but is blocking. public static Mono lookupAndWrite( Map>…
Dave
  • 2,386
  • 1
  • 20
  • 38
3
votes
0 answers

Use Caffeine cache in Spark-streaming

I'm using Caffeine's AsyncLoadingCache to cache lookup data from a database. Now I'd like to integrate this into Spark Streaming. My idea is to let each worker maintain such a cache with a given refresh rate. But how to do that? Is it better to…
Bruckwald
  • 797
  • 8
  • 23
3
votes
1 answer

How to create CaffeineCache object using Java?

I am trying to use Caffeine cache. How to create the object for the Caffeine cache using Java? I am not using any Spring for now in my project.
Bravo
  • 8,589
  • 14
  • 48
  • 85
1
2
3
8 9