Reputation: 7324
Is there any way to load a map entry with a custom TTL using a MapStore
?
Use Case: My map entries each have a custom expiration, at which point the entry is no longer valid (the TTL is not just for limiting the size of the in-memory map, and the TTL is applied to each entry, not to the map config). I set this TTL when I initially put my entry in the map, the expiration is persisted in my underlying persistent map datastore, but I cannot reset this TTL when loading my entries from the database.
public class MyMapStore implements MapStore<MayKey, MapValue> {
@Override
public MapValue load(MayKey key) {
MapValue value = datstore.lookup(key);
Date ttl = value.getExpiration();
// the value has it's own entry-specific TTL, but it seems this can't be used from the MapStore
return value;
}
// . . .
}
The MapLoader
documentation seems to indicate this may not be possible:
Loaded entries will be placed into the distributed map and they will stay in-memory until they are explicitly removed or implicitly evicted (if eviction is configured).
If there is no way to accomplish this with MapStore
, some remaining options seem to be:
MapStore
and instead explicitly lookup entries from my
persistent datastore, loading these values with the desired TTL
MapStore
Is there any other way to accomplish this cleanly/easily with Hazelcast that I'm overlooking?
Upvotes: 3
Views: 2691
Reputation: 7324
As of version 3.6 of Hazelcast, there is not a good way to accomplish this, so I will need to use one of the alternatives identified in the original post.
Hazelcast Issue 7728 has been logged to address this.
See the Hazelcast Google Group for related discussions as well.
Upvotes: 1
Reputation: 102
Did you check : http://docs.hazelcast.org/docs/latest/manual/html-single/index.html#understanding-map-eviction
Evicting Specific Entries The eviction policies and configurations explained above apply to all the entries of a map. The entries that meet the specified eviction conditions are evicted.
But you may want to evict some specific map entries. In this case, you can use the ttl and timeunit parameters of the method map.put(). An example code line is given below.
myMap.put( "1", "John", 50, TimeUnit.SECONDS )
The map entry with the key "1" will be evicted 50 seconds after it is put into myMap.
Upvotes: 0