Commit 8a0351e9 authored by Greg Thomas's avatar Greg Thomas

OF-1416: Ensure that hazelcast cache entries expire correctly

parent 9cf89f04
......@@ -44,6 +44,7 @@ public class ClusteredCache implements Cache {
* The map is used for distributed operations such as get, put, etc.
*/
protected IMap map;
private final int hazelcastLifetimeInSeconds;
private String name;
private long numberOfGets = 0;
......@@ -52,9 +53,11 @@ public class ClusteredCache implements Cache {
*
* @param name a name for the cache, which should be unique per vm.
* @param cache the cache implementation
* @param hazelcastLifetimeInSeconds the lifetime of cache entries
*/
protected ClusteredCache(String name, IMap cache) {
protected ClusteredCache(String name, IMap cache, final int hazelcastLifetimeInSeconds) {
map = cache;
this.hazelcastLifetimeInSeconds = hazelcastLifetimeInSeconds;
setName(name);
}
......@@ -81,7 +84,7 @@ public class ClusteredCache implements Cache {
public Object put(Object key, Object object) {
if (object == null) { return null; }
return map.put(key, object);
return map.put(key, object, hazelcastLifetimeInSeconds, TimeUnit.SECONDS);
}
public Object get(Object key) {
......
......@@ -222,7 +222,7 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
final MapConfig mapConfig = hazelcast.getConfig().getMapConfig(name);
mapConfig.setTimeToLiveSeconds(hazelcastLifetimeInSeconds);
mapConfig.setMaxSizeConfig(new MaxSizeConfig(hazelcastMaxCacheSize, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE));
return new ClusteredCache(name, hazelcast.getMap(name));
return new ClusteredCache(name, hazelcast.getMap(name), hazelcastLifetimeInSeconds);
}
public void destroyCache(Cache cache) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment