Apache Ignite更新已启动缓存的逐出策略(时间)。

huangapple go评论60阅读模式
英文:

Apache Ignite update eviction policy (time) of already started cache

问题

Apache Ignite是否允许更新已启动缓存的淘汰策略(时间)?

我们在系统中有一个实现,我们在Ignite缓存中存储数据。但是,我们需要能够更新现有缓存的淘汰时间,而不会丢失缓存中的数据。在我们的情况下,创建新的缓存不是一个选项。

英文:

Does Apache Ignite allow to update eviction policy (time) of already started cache?

We have an implemenation in our system where we store data in Ignite cache. But we need to be able to update eviction time on existing cache without losing data in the cache. Creating a new cache is not an option in our case.

答案1

得分: 2

更改配置的默认值是不可行的;它是配置的一部分。

但是,你可以随时使用所需的策略创建一个新的缓存包装器。根据文档

CacheConfiguration<Integer, String> cacheCfg = new CacheConfiguration<Integer, String>("myCache");

ignite.createCache(cacheCfg);

IgniteCache cache = ignite.cache("myCache")
        .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MINUTES, 5)));

// 如果缓存不包含键1,条目将在5分钟后过期
cache.put(1, "first value");

IgniteCache cache2 = ignite.cache("myCache")
        .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MINUTES, 2)));

// 如果缓存不包含键2,条目将在2分钟后过期
cache2.put(2, "second value");
英文:

Changing the configured default is not possible; it's part of the configuration.

But, you can always create a new cache wrapper with the required policy. From the docs:

CacheConfiguration&lt;Integer, String&gt; cacheCfg = new CacheConfiguration&lt;Integer, String&gt;(&quot;myCache&quot;);

ignite.createCache(cacheCfg);

IgniteCache cache = ignite.cache(&quot;myCache&quot;)
        .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MINUTES, 5)));

// if the cache does not contain key 1, the entry will expire after 5 minutes
cache.put(1, &quot;first value&quot;);

IgniteCache cache2 = ignite.cache(&quot;myCache&quot;)
        .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MINUTES, 2)));

// if the cache does not contain key 2, the entry will expire after 2 minutes
cache2.put(2, &quot;second value&quot;);

huangapple
  • 本文由 发表于 2023年2月16日 15:39:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75469130.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定