Tag: google guava cache

spring – 使用谷歌番石榴缓存

我试图在我的春季应用程序中使用谷歌番石榴缓存,但结果永远不会缓存。 这是我的步骤: 在conf文件中: @EnableCaching @Configuration public class myConfiguration { @Bean(name = “CacheManager”) public CacheManager cacheManager() { return new GuavaCacheManager(“MyCache”); } } 在课堂上我想使用缓存: public class MyClass extends MyBaseClass { @Cacheable(value = “MyCache”) public Integer get(String key) { System.out.println(“cache not working”); return 1; } } 然后当我打电话时: MyClass m = new MyClass(); m.get(“testKey”); m.get(“testKey”); m.get(“testKey”); 它每次都进入function而不使用缓存:console: cache not […]

如何在将其发送到另一种方法时每隔30秒清空番石榴缓存?

我通过调用add方法从多个线程填充我的guava缓存。 现在从每30秒运行一次的后台线程,我想以primefaces方式将缓存中的任何内容发送到sendToDB方法? 以下是我的代码: public class Example { private final ScheduledExecutorService executorService = Executors .newSingleThreadScheduledExecutor(); private final Cache<Integer, List> cache = CacheBuilder.newBuilder().maximumSize(100000) .removalListener(RemovalListeners.asynchronous(new CustomRemovalListener(), executorService)) .build(); private static class Holder { private static final Example INSTANCE = new Example(); } public static Example getInstance() { return Holder.INSTANCE; } private Example() { executorService.scheduleAtFixedRate(new Runnable() { @Override public […]

java – google guava缓存invalidateAll()和cleanUp()之间的区别

假设我有一个像这样定义的Cache : private static Cache alertsUIDCache = CacheBuilder.newBuilder(). expireAfterAccess(60).build(); 从我读到的内容 (如果我错了请纠正我): 如果在0:00将值写入Cache ,则应在60秒后将其移至“准备被驱逐”状态。 实际从Cache删除值将在下一次缓存修改时发生( 缓存修改究竟是什么?)。 是对的吗? 另外,我不确定invalidateAll()和cleanUp()方法之间有什么区别,有人可以提供解释吗?