caffeine

prefetch all entries in java caffeine cache

风流意气都作罢 提交于 2019-12-25 07:16: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--

Binding @ConfigurationProperties to builder used to create bean

穿精又带淫゛_ 提交于 2019-12-24 19:59:08
问题 I'm creating multiple Caffeine caches like: @Bean public Cache<String, Customer> customerCache() { return Caffeine.newBuilder() .maximumSize(10_000) // other config settings .build(..); } Now I would like to use something like a @ConfigurationProperties(prefix = "cache.customer") to set the builder config options. Where a application property cache.customer.maximum-size: 1000 exists. Is there something smart I can do to map the @ConfigurationProperties to the Caffeine builder? 回答1: You can do

How to extend default Spring Boot CacheManager configuration

大城市里の小女人 提交于 2019-12-10 16:12:49
问题 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 application.properties I have something similar: spring.cache.cache-names=a-cache,b-cache,c-cache, ... spring.cache.caffeine.spec=maximumSize=200,expireAfterWrite=3600s This for common caches. Then I'd like to extend this configuration with custom

How to create a Jcache in Spring Java config?

感情迁移 提交于 2019-12-10 14:21:04
问题 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 CaffeineCachingProvider(); } @Bean(name = "caffeineCacheManager") public JCacheCacheManager getSpringCacheManager() { CacheManager cacheManager = caffeineCachingProvider().getCacheManager(); CaffeineConfiguration<String, List<Product>> caffeineConfiguration = new

How to add entire table to cache in spring

我的未来我决定 提交于 2019-12-08 04:23:44
问题 I have a very small table which is not updated frequently. I want to add this to cache such that it updates every day. I am using spring and caffeine to implement this. I able to load a startup but don't how to refresh it. Please help. @Bean public CacheManager cacheManager() { SimpleCacheManager simpleCacheManager = new SimpleCacheManager(); Cache stringStringCache = new CaffeineCache("name", Caffeine.newBuilder() .recordStats() .maximumSize(100) .expireAfterWrite(1, TimeUnit.DAYS) .build())

How to add entire table to cache in spring

对着背影说爱祢 提交于 2019-12-06 14:48:32
I have a very small table which is not updated frequently. I want to add this to cache such that it updates every day. I am using spring and caffeine to implement this. I able to load a startup but don't how to refresh it. Please help. @Bean public CacheManager cacheManager() { SimpleCacheManager simpleCacheManager = new SimpleCacheManager(); Cache stringStringCache = new CaffeineCache("name", Caffeine.newBuilder() .recordStats() .maximumSize(100) .expireAfterWrite(1, TimeUnit.DAYS) .build()); simpleCacheManager.setCaches(Collections.singleton(stringStringCache)); return simpleCacheManager; }

Is it possible to set a different specification per cache using caffeine in spring boot?

坚强是说给别人听的谎言 提交于 2019-12-03 08:48:23
问题 I have a simple sprint boot application using spring boot 1.5.11.RELEASE with @EnableCaching on the Application Configuration class. pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> </dependency> application.properties spring.cache.type=caffeine spring.cache.cache-names=cache-a,cache-b spring.cache.caffeine.spec

Is it possible to set a different specification per cache using caffeine in spring boot?

北慕城南 提交于 2019-12-02 22:43:48
I have a simple sprint boot application using spring boot 1.5.11.RELEASE with @EnableCaching on the Application Configuration class. pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> </dependency> application.properties spring.cache.type=caffeine spring.cache.cache-names=cache-a,cache-b spring.cache.caffeine.spec=maximumSize=100, expireAfterWrite=1d Question My question is simple, how can one specify a different size

高性能Java缓存----Caffeine

匿名 (未验证) 提交于 2019-12-02 20:59:24
简单介绍 Caffeine是新出现的一个高性能的Java缓存,有了它完全可以代替Guava Cache,来实现更加高效的缓存;Caffeine采用了W-TinyLFU回收策略,集合了LRU和LFU的优点,提供了一个最佳的命中率,在效率上可以秒杀Guava Cache,下面盗取一个来自网络的性能比较的截图: 如何使用 Caffeine使用非常简单,跟Guava Cache的API使用几乎一致,下面就话不多说直接,进入代码使用和学习中。 手动加载 import java.util.concurrent.TimeUnit; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; public class CaffeineManualLoadTest { public static void main(String[] args) { // 手动加载 Cache<String, Object> manualCache = Caffeine.newBuilder() .expireAfterWrite(5, TimeUnit.SECONDS) .build(); String key = "test1"; // 根据key查询一个缓存

Multiple Caffeine LoadingCaches added to Spring CaffeineCacheManager

旧巷老猫 提交于 2019-11-30 13:07:34
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 loaders for each cache. Is it possible to add multiple loading caches to a Spring cache manager? If so, then how? CaffeineCacheManager cacheManage = new CaffeineCacheManager(); LoadingCache<String, Optional<Edition>> loadingCache1 = Caffeine.newBuilder() .maximumSize(150) .refreshAfterWrite(5, TimeUnit.MINUTES) .build(test -> this.testRepo.find(test));