英文:
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<Integer, String> cacheCfg = new CacheConfiguration<Integer, String>("myCache");
ignite.createCache(cacheCfg);
IgniteCache cache = ignite.cache("myCache")
.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, "first value");
IgniteCache cache2 = ignite.cache("myCache")
.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, "second value");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论