caffeine

Register Caffeine Cache in Spring Actuator (CacheManager)

一曲冷凌霜 提交于 2021-02-18 19:00:23
问题 We're using Spring Boot 2 and Spring Actuator. When creating a cache like the following: @Bean public CaffeineCache someCache() { return new CaffeineCache("my-cache", Caffeine.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.SECONDS) .build()); } it is registered into Spring Actuator and can be accessed and handle via endpoints: ❯ http GET localhost:8080/actuator/caches { "cacheManagers": { "cacheManager": { "caches": { "my-cache": { "target": "com.github.benmanes.caffeine.cache

Register Caffeine Cache in Spring Actuator (CacheManager)

一个人想着一个人 提交于 2021-02-18 19:00:07
问题 We're using Spring Boot 2 and Spring Actuator. When creating a cache like the following: @Bean public CaffeineCache someCache() { return new CaffeineCache("my-cache", Caffeine.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.SECONDS) .build()); } it is registered into Spring Actuator and can be accessed and handle via endpoints: ❯ http GET localhost:8080/actuator/caches { "cacheManagers": { "cacheManager": { "caches": { "my-cache": { "target": "com.github.benmanes.caffeine.cache

Register Caffeine Cache in Spring Actuator (CacheManager)

一个人想着一个人 提交于 2021-02-18 18:59:54
问题 We're using Spring Boot 2 and Spring Actuator. When creating a cache like the following: @Bean public CaffeineCache someCache() { return new CaffeineCache("my-cache", Caffeine.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.SECONDS) .build()); } it is registered into Spring Actuator and can be accessed and handle via endpoints: ❯ http GET localhost:8080/actuator/caches { "cacheManagers": { "cacheManager": { "caches": { "my-cache": { "target": "com.github.benmanes.caffeine.cache

Dynamically toggling recording stats on Caffeine Cache

陌路散爱 提交于 2021-02-11 13:52:43
问题 I would like to be able to dynamically toggle the recording of stats of Caffeine Caches on demand via REST endpoint, or JMX Method We have a large scale application where we use several instances of Caffeine Caches. We could use every possible performance upgrade, so having it in constant recording seems redundant. Especially if JavaDoc says recording has a performance cost. After my analysis I think it is not directly supported. Or is it? I have 2 goals for stats, 1st one is to be able to

Dynamically toggling recording stats on Caffeine Cache

我是研究僧i 提交于 2021-02-11 13:51:31
问题 I would like to be able to dynamically toggle the recording of stats of Caffeine Caches on demand via REST endpoint, or JMX Method We have a large scale application where we use several instances of Caffeine Caches. We could use every possible performance upgrade, so having it in constant recording seems redundant. Especially if JavaDoc says recording has a performance cost. After my analysis I think it is not directly supported. Or is it? I have 2 goals for stats, 1st one is to be able to

Caffeine - how expires Cached values only after creation time

牧云@^-^@ 提交于 2020-12-15 06:18:45
问题 Caffeine has expiresAfterWrite method which looks at last write time. I want it to look only at the creation time. So when the first entry comes then entry will be expired after a fixed amount of time without looking at the number of updates on this entry. Is this possible? 回答1: Yes, but requires using the more advanced Expiry api. In the below example, a newly created entry has a fixed 5 minute lifetime. This is done by returning currentDuration on an update or read. LoadingCache<Key, Graph>

How do I use an async cache with Kotlin coroutines?

谁说胖子不能爱 提交于 2020-03-15 07:28:40
问题 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 I would need to implement uses CompletableFuture . Meanwhile, the method I want to call to load the cache entries is a suspend function. I can bridge the gap like this: abstract class SuspendingCacheLoader<K, V>: AsyncCacheLoader<K, V> { abstract

How do I use an async cache with Kotlin coroutines?

你说的曾经没有我的故事 提交于 2020-03-15 07:28:10
问题 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 I would need to implement uses CompletableFuture . Meanwhile, the method I want to call to load the cache entries is a suspend function. I can bridge the gap like this: abstract class SuspendingCacheLoader<K, V>: AsyncCacheLoader<K, V> { abstract

Caffeine versus Guava cache

倾然丶 夕夏残阳落幕 提交于 2020-01-22 09:24:25
问题 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 expiration Caffeine use a scheduled executor to perform appropriate maintenance operations in background? 回答1: The main difference is because Caffeine uses ring buffers to record & replay events, whereas Guava uses ConcurrentLinkedQueue . The intent

prefetch all entries in java caffeine cache

安稳与你 提交于 2019-12-25 07:17:04
问题 I am trying to build a cache using https://github.com/ben-manes/caffeine, where I need to fetch all entries during boot up time and I do not know all the keys before hand. My CachLoader has something like this and trying to cache all at startup. But looks like I will need to know all the keys before hand, if I want to prefetch all entries in to cache? Am I missing anything? So, say I call cache.getAll(10) and only 10-->100 will be cached even though the loadAll method returns 3 entries (10--