0

ここで助けが必要です。一定時間使用されていないときに要素(キー)を削除する必要があるプロジェクトに取り組んでいます。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 を使用しています

スクリーンショット 0

スクリーンショット 1

スクリーンショット 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);
    }
4

2 に答える 2

2

永久属性が「true」に設定されている場合、timeToLive と timeToIdle がオーバーライドされるため、有効期限が切れることはありません。( https://www.ehcache.org/documentation/2.8/configuration/configuration.html ) そして、構成パラメーターの「eternal」には「true」の値があります。

于 2019-08-08T11:23:03.253 に答える