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:
- Do not use
MapStore
and instead explicitly lookup entries from my persistent datastore, loading these values with the desired TTL- This may be feasible, but with this approach, I'm no longer able to take
advantage of the benefits of
MapStore
- This may be feasible, but with this approach, I'm no longer able to take
advantage of the benefits of
- Run a background thread which periodically explicitly evicts these expired entries, rather than relying on Hazelcast's automatic eviction
- This is just a lot of overhead (additional thread, querying and entry processing) and requires that my application code checks the validity of the entry prior to use (since expired entries may exist in the map)
Is there any other way to accomplish this cleanly/easily with Hazelcast that I'm overlooking?