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
1
vote
1 answer

Caffeine - How to set for each entity its own "expiration time"

We used to use the guava cache and we want to change it to caffeine. We want to set for each entity its own "expiration time", something like - put(K key, V value, long expiration_time). I saw the 3 functions above and I wonder what exactly they are…
May Merari
  • 11
  • 2
1
vote
0 answers

Async caching using caffeine

I came across asynchronous caching using Caffeine library. Following https://www.programcreek.com/java-api-examples/?api=com.github.benmanes.caffeine.cache.AsyncCacheLoader, I have following code snippet: import…
harry123
  • 760
  • 1
  • 7
  • 22
1
vote
1 answer

Caffeine cache delayed entries expiration with after-creation policy

I'm using Caffeine lib for caching purposes with 1-sec expiration interval after entry creation. It turned out that entries expire with some delay sometimes it could take up to 2x more time to expire instead of configured 1-sec interval. Based on my…
MeetJoeBlack
  • 2,804
  • 9
  • 40
  • 66
1
vote
1 answer

Caffeine: Use stale values when AsyncLoader fails to refresh

I want to configure my Caffeine cache to return stale results when loader fails to refresh the cache. The following Kotlin code demonstrates the case: @Test fun `completeble future`() = runBlocking { val cache =…
alisabzevari
  • 8,008
  • 6
  • 43
  • 67
1
vote
1 answer

Caffeine cache, perform eviction of expired element only when put succeds

I use Caffeine cache to cache data coming from the DB that need to served to a rest endpoint. So the cache is updated ONLY on read operations on the DB. In the nominal case, I want the cache to take the lead of responding until the data is not older…
Monta
  • 1,136
  • 1
  • 12
  • 28
1
vote
2 answers

Caffeine Cache - How to get information of creation date of an element

Is there any way to access the creation timestamp of an element from the CaffeineCache? Kind of cache.get("x").getTimestamp()?
Monta
  • 1,136
  • 1
  • 12
  • 28
1
vote
0 answers

Does Spring boot 2.2.4 support Caffeine AsyncCache implementation

I have just started working with Caffeine. I see CaffeineCache class in Spring Boot only support implementations of Cache interface from Caffeine as shown in the code below, but I would like to know if Spring Boot supports implementations of…
1
vote
2 answers

Caffeine Springboot integration

we are using caffeine to replace the ConcurrentHashMap cache, which is default in current springboot. We are dynamically creating caches using the @Cacheable(cacheNames = { "..." }) annotation. I am trying to set the recordStats property, since we…
DocJones
  • 649
  • 7
  • 26
1
vote
1 answer

com.github.benmanes.caffeine.cache.maximumsize(long maximumSize) allows max records up to record-count of maximumSize?

https://www.javadoc.io/doc/com.github.ben-manes.caffeine/caffeine/1.0.0/com/github/benmanes/caffeine/cache/Caffeine.html#maximumSize-long- says that maximumSize() specifies the maximum number of entries the cache may contain. Note that the cache may…
gosachin1
  • 61
  • 1
  • 8
1
vote
1 answer

Spring Data: Hibernate query cache not working for derived queries

I am trying to setup Hibernate query cache for queries derived by method name in Spring Data, but the query cache is never used, or doesn't even seem to be active. I am using Spring Boot 2.2.1, Kotlin 1.3.50, and Caffeine with the JCache extension…
gotson
  • 3,613
  • 1
  • 23
  • 40
1
vote
0 answers

Caffeine: Memoize or Cache Builder a Big List of Items?

As a disclaimer, I'm new to Caffeine and exploring out this lightweight approach. I have a collection that is fetched from a database that consists of more than 20K of simple ItemLOV two-attribute objects. They are pulled, converted / cast…
Melvin Mah
  • 105
  • 2
  • 13
1
vote
1 answer

Caffeine cache: write() never get called

My cache is built with writer: appsCache = Caffeine.newBuilder() .writer(this) .maximumSize(10) .expireAfterWrite(Duration.ofSeconds(64000)) .build(this); In my test, I'm loading 10 items and then waiting (with an…
IsaacLevon
  • 2,260
  • 4
  • 41
  • 83
1
vote
1 answer

Caffeine cache "cannot be cast to org.springframework.cache.Cache"

I am attempting to use Spring Boot caching. I have a cached class: @Component public class GlobalAssetIdCache { private static final Logger LOG = LogManager.getLogger(GlobalAssetIdCache.class); @Cacheable(value = "GLOBAL_ASSET_ID",…
markthegrea
  • 3,731
  • 7
  • 55
  • 78
1
vote
0 answers

CaffeineCache is not refreshed immediately after put operation in Spring Boot application

I have a random issue with CaffeineCache in my Spring Boot application. The problem is with an integration test that makes next find user delete it find it again It seems that sometimes cache doesn't not refreshes on time before the second call…
Vitalii
  • 10,091
  • 18
  • 83
  • 151
1
vote
1 answer

How to make cache depends on other caches on startup of spring application

In our multi module project, we have different cache present in different modules. And we fill all these caches on server startup in @PostConstruct. Now some cache depends on some other cache which may present in different modules. So it requires…
Avinash Kharche
  • 411
  • 9
  • 25
1 2 3
8 9