Voulait effacer le cache de noisetier. Ainsi, une fois que le cache atteint Max Entries ou Max Heap Size, videz-le dans un fichier.Impossible de vider le cache de haselcast une fois qu'il a atteint le nombre configuré d'entrées/la taille
configurationdans hazelcast.xml
<map name="TEST_CACHE">
<max-size policy="PER_NODE">3</max-size>
<eviction-policy>LFU</eviction-policy>
</map>
Code d'essai
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");
}
}
et entryEvicted je suis seulement obtenir le 3ème objet d'entrée
Entry EVICTED :: 1
3 : [email protected]
est-il possible de rincer le contenu du cache dans un fichier/db une fois la taille maximale atteinte?