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 { ...@@ -44,6 +44,7 @@ public class ClusteredCache implements Cache {
* The map is used for distributed operations such as get, put, etc. * The map is used for distributed operations such as get, put, etc.
*/ */
protected IMap map; protected IMap map;
private final int hazelcastLifetimeInSeconds;
private String name; private String name;
private long numberOfGets = 0; private long numberOfGets = 0;
...@@ -52,9 +53,11 @@ public class ClusteredCache implements Cache { ...@@ -52,9 +53,11 @@ public class ClusteredCache implements Cache {
* *
* @param name a name for the cache, which should be unique per vm. * @param name a name for the cache, which should be unique per vm.
* @param cache the cache implementation * @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; map = cache;
this.hazelcastLifetimeInSeconds = hazelcastLifetimeInSeconds;
setName(name); setName(name);
} }
...@@ -81,7 +84,7 @@ public class ClusteredCache implements Cache { ...@@ -81,7 +84,7 @@ public class ClusteredCache implements Cache {
public Object put(Object key, Object object) { public Object put(Object key, Object object) {
if (object == null) { return null; } if (object == null) { return null; }
return map.put(key, object); return map.put(key, object, hazelcastLifetimeInSeconds, TimeUnit.SECONDS);
} }
public Object get(Object key) { public Object get(Object key) {
......
...@@ -222,7 +222,7 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy { ...@@ -222,7 +222,7 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
final MapConfig mapConfig = hazelcast.getConfig().getMapConfig(name); final MapConfig mapConfig = hazelcast.getConfig().getMapConfig(name);
mapConfig.setTimeToLiveSeconds(hazelcastLifetimeInSeconds); mapConfig.setTimeToLiveSeconds(hazelcastLifetimeInSeconds);
mapConfig.setMaxSizeConfig(new MaxSizeConfig(hazelcastMaxCacheSize, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE)); 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) { 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