ここで助けが必要です。一定時間使用されていないときに要素(キー)を削除する必要があるプロジェクトに取り組んでいます。timeToLiveSeconds と timeToIdleSeconds の両方を 60 秒にしてみました。また、timeToLiveSeconds=60 のみと timeToIdleSeconds=60 のみで試しました。しかし、キャッシュにはまだその要素が表示されます。
fyi: キャッシュされたすべての要素を画面に表示するコードがいくつかあります。
スクリーンショット 0: アクションの REST サービスを呼び出す前。期待: 要素はキャッシュ Web ページに表示されるべきではありません – 期待どおりに動作します
スクリーンショット 1: REST サービスを呼び出してアクションを実行した後。期待: Web ページのキャッシュ リストの要素を参照してください – 期待どおりに動作します
60秒間アイドル状態になりました(RESTサービスを呼び出さないでください。要素が60秒間使用されないことを意味します)
スクリーンショット 2: キャッシュ Web ページを更新します。期待: 要素はキャッシュ Web ページに表示されるべきではありません – 期待どおりに動作しません
- 要素は AF2TDU2001 を意味します
- ehcache 2.5.2 を使用しています
これが私のコードです:
/**
*
* @param cacheName
* @param diskPersistent
*/
private static void addCache(String cacheName, boolean diskPersistent) {
/*
@param name - the name of the cache. Note that "default" is a reserved name for the defaultCache.
@param maxElementsInMemory - the maximum number of elements in memory, before they are evicted (0 == no limit)
@param memoryStoreEvictionPolicy - one of LRU, LFU and FIFO. Optionally null, in which case it will be set to LRU.
@param overflowToDisk - whether to use the disk store
@param diskStorePath - this parameter is ignored. CacheManager sets it using setter injection.
@param eternal - whether the elements in the cache are eternal, i.e. never expire
@param timeToLiveSeconds - the default amount of time to live for an element from its creation date
@param timeToIdleSeconds - the default amount of time to live for an element from its last accessed or modified date
@param diskPersistent - whether to persist the cache to disk between JVM restarts
@param diskExpiryThreadIntervalSeconds - how often to run the disk store expiry thread. A large number of 120 seconds plus is @param recommended
@param registeredEventListeners - a notification service. Optionally null, in which case a new one with no registered listeners will @param be created.
@param bootstrapCacheLoader - the BootstrapCacheLoader to use to populate the cache when it is first initialised. Null if none is @param required.
@param maxElementsOnDisk - the maximum number of Elements to allow on the disk. 0 means unlimited.
@param diskSpoolBufferSizeMB - the amount of memory to allocate the write buffer for puts to the DiskStore.
*/
Cache cache = new Cache(cacheName,
10000, // maxElementsInMemory
MemoryStoreEvictionPolicy.LRU, // memoryStoreEvictionPolicy
false, // overflowToDisk
diskStorePath,
true, // eternal
60, // timeToLiveSeconds
60, // timeToIdleSeconds
false, // diskPersistent
1, // diskExpiryThreadIntervalSeconds
null,
null,
0, // bootstrapCacheLoader
0, // maxElementsOnDisk
false);
cacheManager.addCache(cache);
}