有没有办法为我在 ignitecache 中插入的不同元素设置不同的到期时间?

Posted

技术标签:

【中文标题】有没有办法为我在 ignitecache 中插入的不同元素设置不同的到期时间?【英文标题】:Is there a way to put up different expiry times for different elements I insert in ignitecache? 【发布时间】:2020-11-01 10:39:07 【问题描述】:

我可以像在 ehcache 中那样插入具有不同到期时间的元素吗

例如:

Cache : add element1 //5秒后过期

cache : add element2 //15秒后过期

cache : add element3 //在 'x' 秒/分钟后过期

如果没有,你能建议任何替代缓存来解决这个问题吗?

我也打算使用 ehcache,但结果它不支持主动/急切到期。

【问题讨论】:

【参考方案1】:

缓存条目有单独的过期策略,使用IgniteCache.withExpiryPolicy

cache.withExpiryPolicy(new CreatedExpiryPolicy(new Duration(SECONDS, 5))).put(1, 1);

cache.withExpiryPolicy(new CreatedExpiryPolicy(new Duration(SECONDS, 15))).put(2, 2);

【讨论】:

以上是关于有没有办法为我在 ignitecache 中插入的不同元素设置不同的到期时间?的主要内容,如果未能解决你的问题,请参考以下文章