google-guava-cache

spring - using google guava cache

為{幸葍}努か 提交于 2019-12-06 02:16:10
I'm trying to use google guava cache in my spring app, but result is never caching. This are my steps: in conf file: @EnableCaching @Configuration public class myConfiguration { @Bean(name = "CacheManager") public CacheManager cacheManager() { return new GuavaCacheManager("MyCache"); } } In class I want to use caching: public class MyClass extends MyBaseClass { @Cacheable(value = "MyCache") public Integer get(String key) { System.out.println("cache not working"); return 1; } } Then when I'm calling: MyClass m = new MyClass(); m.get("testKey"); m.get("testKey"); m.get("testKey"); It's entering

compiler error when using Google guava from scala code

断了今生、忘了曾经 提交于 2019-12-02 04:25:16
问题 I m using Google Guava from a scala code. And an issue occurs when I m trying to use Int as a key type like in the example: CacheBuilder.newBuilder() .maximumSize(2) .expireAfterWrite(24, TimeUnit.HOURS) .build( new CacheLoader[Int, String] { def load(path: Int): String = { path + "hello" } } ) It seems to be fine, but the inferred type of created object is LoadingCache[Int with AnyRef, String] : val cache: LoadingCache[Int with AnyRef, String] = CacheBuilder.newBuilder() .maximumSize(2)

How to empty Guava cache every 30 seconds while sending it to another method?

独自空忆成欢 提交于 2019-12-02 01:16:11
I am populating my guava cache from multiple threads by calling add method. Now from the background thread which runs every 30 seconds, I want to send whatever is there in the cache to sendToDB method atomically? Below is my code: public class Example { private final ScheduledExecutorService executorService = Executors .newSingleThreadScheduledExecutor(); private final Cache<Integer, List<Process>> cache = CacheBuilder.newBuilder().maximumSize(100000) .removalListener(RemovalListeners.asynchronous(new CustomRemovalListener(), executorService)) .build(); private static class Holder { private

java - google guava cache difference between invalidateAll() and cleanUp()

ぃ、小莉子 提交于 2019-12-01 06:06:46
Say I have a Cache that is defined like this: private static Cache<String, Long> alertsUIDCache = CacheBuilder.newBuilder(). expireAfterAccess(60).build(); From what I read (please correct me if I am wrong): If value is written to Cache at 0:00, it should be moved to "ready to be evicted" status after 60 seconds. The actual removing of the value from the Cache will happen at the next cache modification (what is exactly is cache modification ?). is that right? Also, I am not sure what the difference between the invalidateAll() and the cleanUp() methods, can someone provide an explanation? vahid