在我的播放应用程序中使用cacheApi
,我想知道我是否可以有一些超时缓存清理?如何在play framework中使用cacheApi设置清理缓存超时?
进出口使用的cacheApi
对象的方法if the data is in cache bring from cache, if not, so go get it from the server with an api call
,现在我想每24个小时清理缓存,能够从服务器带来了新的数据。
我是如何完成这样的事情的?
在我的播放应用程序中使用cacheApi
,我想知道我是否可以有一些超时缓存清理?如何在play framework中使用cacheApi设置清理缓存超时?
进出口使用的cacheApi
对象的方法if the data is in cache bring from cache, if not, so go get it from the server with an api call
,现在我想每24个小时清理缓存,能够从服务器带来了新的数据。
我是如何完成这样的事情的?
我用这个代码配置超时时间:
CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.heap(100))
.withExpiry(Expirations.timeToLiveExpiration(Duration.of(20, TimeUnit.SECONDS)))
.build();
播放框架V2.5:使用CacheApi.set方法,并传递所需的到期时间设定时间为缓存值离开(TTL)。
Play Framework v2.6:使用SyncCacheApi.set或AsyncCacheApi.set。您也可以创建计时器并在一段时间后致电AsyncCacheApi.removeAll(但尚不清楚 - 可以删除刚添加的值(比如说前5分钟添加)吗?
默认情况下,过期时间是无限的 - 它永远不会从缓存中删除!