使用 TTL 加载 Hazelcast MapStore

Hazelcast MapStore Load with TTL

有什么方法可以 load a map entry with a custom TTL 使用 MapStore 吗?

用例:我的每个地图条目都有自定义到期时间,此时条目不再有效(TTL 不仅用于限制内存中地图的大小,而且 TTL 应用于每个入口,而不是地图配置)。当我最初 put 我在地图中的条目时,我设置了这个 TTL,过期在我的底层持久地图数据存储中持续存在,但是当我从数据库加载我的条目时我无法重置这个 TTL。

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;
    }

    // . . .

}

MapLoader 文档似乎表明这可能是不可能的:

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).

如果无法使用 MapStore 完成此操作,剩下的一些选项似乎是:

有没有其他方法可以使用我忽略的 Hazelcast 来完成此 cleanly/easily?

你检查了吗:http://docs.hazelcast.org/docs/latest/manual/html-single/index.html#understanding-map-eviction

逐出特定条目 上面解释的逐出策略和配置适用于映射的所有条目。满足指定逐出条件的条目被逐出。

但您可能想要驱逐某些特定的地图条目。在这种情况下,您可以使用方法 map.put() 的 ttl 和 timeunit 参数。下面给出了示例代码行。

myMap.put( "1", "John", 50, TimeUnit.SECONDS )

键为“1”的地图条目将在放入 myMap 50 秒后被逐出。

从 Hazelcast 的 3.6 版开始,还没有一个很好的方法来完成这个,所以我需要使用原始 post 中确定的替代方法之一。

Hazelcast Issue 7728 已记录以解决此问题。

有关相关讨论,请参阅 Hazelcast Google Group