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

Cannot create simple cache with Caffeine

I'm trying to create a simple (non-loading) cache with Caffeine. Cache countsCache = CacheBuilder.newBuilder().build(); This fails to compile, with the Error reported: Error:(42, 31) java: incompatible types: no…
L. Blanc
  • 2,150
  • 2
  • 21
  • 31
2
votes
1 answer

How are multiple expiration criteria set in Caffeine Expiry?

I'm using Caffeine v2.8.5 and I want to create a cache with a variable expiry based on: the creation/update of the value and the last access (read) of this value. Whatever comes first should trigger the removal of that entry. The cache will be…
Scrayos
  • 101
  • 2
  • 9
2
votes
1 answer

Define multiple caches configurations with Spring and Caffeine

I need to use several caches in my service for different uses. I'm looking for a way to separate their configurations like maximumSize and expireAfterWrite. I'm using Spring and Kubernetes, and in the deploy.yaml I have this: spring: main: …
OLY
  • 65
  • 2
  • 7
2
votes
0 answers

Caffeine Cache with Spring Boot

I have my DAO layers with an expensive method as followed: @Component @CacheConfig(cacheNames = {"userStories"}) public class UserStoryDaoImpl implements IUserStoryDao { @Override @Cacheable public List
Einstein_AB
  • 396
  • 5
  • 22
2
votes
1 answer

Caffeine java cache - how to load new value first and then return new one instead of old value, if refreshAfterWrite expired

I'm trying to use caffeine cache and have a problem: Let's say cache is empty and I query for a value, it uses loader and loads a new value into the cache, after 2 days have passed I query for the same value and I get OLD value first then refresh is…
2
votes
1 answer

Is there a way to enable Caffeine MBean registration?

I am using Scaffeine in my project (https://github.com/blemale/scaffeine), a Scala wrapper for Caffeine (https://github.com/ben-manes/caffeine). I also have a prometheus JMX collector embedded in my metrics API…
Berni
  • 357
  • 3
  • 10
2
votes
1 answer

Dynamically resize a Caffeine Cache

I am currently migrating from ConcurrentLinkedHashMap to Caffeine and I am stuck on trying to find an equivalent feature of setCapacity _myCache.setCapacity(newCacheSize); Is there a way to do the same in Caffeine ? Should I copy my current cache…
Frederic
  • 2,015
  • 4
  • 20
  • 37
2
votes
1 answer

Asynchronous Caffeine cache with statistics

Following this blog post about implementing a Caffeine async cache, we wanted to get the statistical data from the cache. We are using version 2.7.0 of Caffeine However, it seems that the AsyncCache has no access to its statistics: private…
riorio
  • 6,500
  • 7
  • 47
  • 100
2
votes
2 answers

Cache not working properly using Reactor and Caffeine

I need to check some endpoints in different intervals, so I set up the Caffeine's cache builder . this.localeWeatherCache =…
emerson
  • 75
  • 1
  • 5
2
votes
1 answer

Caffeine cache - many keys to single value

I have Caffeine cache with Key->Value mapping. There are multiple implementations of Key interface with different equals methods. In order to delete value from cache based on someOtherVal, I had to use code like…
Bojan Vukasovic
  • 2,054
  • 22
  • 43
2
votes
2 answers

How can I cache items in RxJava and avoid cache stampede?

Let's say I've got the following code: Entity getEntity(GUID entityId) { Entity entity = entityLRUCache.get(entityId); if (entity == null) { entity = longLoadFromDatabase(entityId); entityLRUCache.put(entityId, entity); } return…
Alex Kokorin
  • 459
  • 5
  • 15
2
votes
1 answer

Behaviour of Caffeine Cache.asMap views

The Javadoc says: Returns a view of the entries stored in this cache as a thread-safe map. Modifications made to the map directly affect the cache. What I'm missing is the information about whether access to the view influences the admission and…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
2
votes
0 answers

Refresh all entries in Caffeine / Scaffeine

I'm working with the Scala version of Caffeine, Scaffeine. I'm trying to populate a cache, in a way that it should reload all the values after expiration (10sec in the test). I probably I could use Guava's Suppliers.memoizeWithExpiration but I'd…
Bruckwald
  • 797
  • 8
  • 23
2
votes
1 answer

Why I have cache misses in Service using Spring Cache

I have configured my cache as follows: @Configuration @EnableCaching public class CacheConfig { @Bean(name = "caffeineCachingProvider") public CachingProvider caffeineCachingProvider() { return…
marknorkin
  • 3,904
  • 10
  • 46
  • 82
1
vote
0 answers

Error executing Caffeine CacheBuilder configuration class when migrated to Kotlin

I am migrating to Kotlin CacheBuilder, a Spring Boot configuration class for CaffeineCache @Configuration @EnableCaching open class CacheBuilder { @Bean open fun caffeineConfig(): Caffeine { return…
1 2
3
8 9