Add eviction configuration for the Map.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package io.refectoring.cache.embedded;
|
||||
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.config.MapConfig;
|
||||
import com.hazelcast.config.*;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.map.IMap;
|
||||
@@ -16,7 +15,7 @@ public class HazelcastNode {
|
||||
|
||||
public String put(String number, Car car){
|
||||
IMap<Object, Object> map = hzInstance.getMap(CARS);
|
||||
return (String) map.put(number, car);
|
||||
return (String) map.putIfAbsent(number, car);
|
||||
}
|
||||
|
||||
public Car get(String key){
|
||||
@@ -26,10 +25,22 @@ public class HazelcastNode {
|
||||
|
||||
public Config createConfig() {
|
||||
Config config = new Config();
|
||||
MapConfig mapConfig = new MapConfig(CARS);
|
||||
mapConfig.setTimeToLiveSeconds(20);
|
||||
mapConfig.setMaxIdleSeconds(360);
|
||||
config.addMapConfig(mapConfig);
|
||||
config.addMapConfig(mapConfig());
|
||||
return config;
|
||||
}
|
||||
|
||||
private MapConfig mapConfig() {
|
||||
MapConfig mapConfig = new MapConfig(CARS);
|
||||
mapConfig.setEvictionConfig(evictionConfig());
|
||||
mapConfig.setTimeToLiveSeconds(20);
|
||||
mapConfig.setMaxIdleSeconds(360);
|
||||
return mapConfig;
|
||||
}
|
||||
|
||||
private EvictionConfig evictionConfig() {
|
||||
EvictionConfig evictionConfig = new EvictionConfig();
|
||||
evictionConfig.setEvictionPolicy(EvictionPolicy.LFU);
|
||||
evictionConfig.setSize(2000);
|
||||
return evictionConfig;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user