缓存中的条目未驱逐

时间:2019-01-25 15:16:58

标签: infinispan

我正在使用Infinispan(9.4.5.Final)将数据本地存储在缓存中。

为此,我正在使用这段代码(来自https://www.baeldung.com/infinispan

private Configuration passivatingConfiguration() {
return new ConfigurationBuilder()
  .memory().evictionType(EvictionType.COUNT).size(1)
  .persistence() 
  .passivation(true)    // activating passivation
  .addSingleFileStore() // in a single file
  .purgeOnStartup(true) // clean the file on startup
  .location(System.getProperty("java.io.tmpdir")) 
  .build();}

每次我将某些内容放入缓存时,我都会打印其大小:

cache.size()

缓存大小应恒定为1,但不能停止增加...

我正在尝试另一段代码:

private Configuration evictingConfiguration() {
return new ConfigurationBuilder()
  .memory().evictionType(EvictionType.COUNT).size(1)
  .build();}

而且...正在运行...缓存的大小始终为1。

我想固定内存。 是否有人遇到相同的问题?

1 个答案:

答案 0 :(得分:1)

您已经配置了缓存存储。如果您注意到javadoc提到的大小,则在调用https://docs.jboss.org/infinispan/10.0/apidocs/org/infinispan/Cache.html#size--

中包括缓存加载器

如果您只想检索内存中条目的大小,请尝试以下操作:

cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).size();
相关问题