0

ヘーゼルキャストのキャッシュをクリアしたかった。そのため、キャッシュが最大エントリまたは最大ヒープ サイズに達したら、それをファイルにフラッシュします。

hazelcast.xml の構成

<map name="TEST_CACHE">
    <max-size policy="PER_NODE">3</max-size>
    <eviction-policy>LFU</eviction-policy> 
</map>

テストコード

public class Test implements EntryEvictedListener , Serializable{

    private static final long serialVersionUID = -1927328346902661527L;
    private static HazelcastInstance hazelcastInstance = HazelCacheUtil
            .getHazelCacheInstance();
    private static volatile IMap<Object, Object> hazel_cache = hazelcastInstance
            .getMap("TEST_CACHE");

    public static void main(String[] args) throws Exception {
        hazel_cache.addEntryListener(new Test(),true);

        for (int i = 0; i < 3; i++) {
            hazel_cache.put(i+1, new Test());
        }
        System.out.println(hazel_cache);

        System.out.println("");
        for (Entry e : hazel_cache.entrySet()) {
            System.out.println(e.getKey() + " : " + e.getValue());
        }
    }

    @Override
    public void entryEvicted(EntryEvent e) {
        System.out.println(e.getKey()+" : "+e.getOldValue()+"\n");
    }
}

entryEvicted では、3 番目のエントリ オブジェクトのみを取得しています

 Entry EVICTED :: 1
3 : com.test.CAO.Test@5a6b6126

最大サイズに達したら、キャッシュの内容をファイル/データベースにフラッシュする方法はありますか?

4

1 に答える 1