在我的播放應用程序中使用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分鐘添加)嗎?
默認情況下,過期時間是無限的 - 它永遠不會從緩存中刪除!