【问题标题】:ehcache write-behind behaviourehcache 后写行为
【发布时间】:2014-09-29 04:32:59
【问题描述】:

我正在使用基于 EhCache 的 cacheWriter 来实现后写缓存。

这里是配置:

<cache name="CACHE_JOURNALS" 
    maxElementsInMemory="1000"
    eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120"
    overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false"
    diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU">
        <cacheWriter writeMode="write-behind"
            maxWriteDelay="2" 
            rateLimitPerSecond="20" 
            writeCoalescing="true"
            writeBatching="false" 
            writeBatchSize="1" 
            retryAttempts="2"
            retryAttemptDelaySeconds="2">
            <cacheWriterFactory
                class="JournalCacheWriterFactory"
                properties="just.some.property=test; another.property=test2"
                propertySeparator=";" />
        </cacheWriter>
    </cache>

在我做一个 cache.putWithWriter 之后

cache.putWithWriter(new Element(key, newvalue));

另一个线程倾向于使用'key'从缓存中读取

观察:

  • 如果
  • 如果 > 2s 那么我得到更新的值(newvalue)

似乎只有在写入数据存储后才使用 'key':newvalue 更新缓存。

  • Q1. 这是 write-behind 的预期行为吗?
  • Q2. 有什么办法让它尽快用 'key':newvalue 更新缓存 随着“putWithWriter”调用完成,然后进行延迟写入 后面。

documentation看来,暗示的是后者。

【问题讨论】:

    标签: ehcache


    【解决方案1】:

    Q1:不。我什至不知道这会如何发生!

    Q2:不适用,因为您观察到的行为不是预期的行为,但新值应该可以立即在缓存中观察到。

    您是否可以将此缓存与某种类型的读取一起使用,并实际观察缓存的条目被驱逐/过期并实际使用数据存储区中的旧值重新填充?

    【讨论】:

      【解决方案2】:

      这是我的一个幼稚错误,调用@Cacheble方法的代码来自同一个spring服务。

      Spring 不会拦截来自同一服务的调用。

      我重构了启用缓存的代码,它按预期工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-23
        • 2011-02-03
        • 1970-01-01
        • 2016-11-22
        • 2012-07-18
        • 2015-10-22
        • 2021-07-30
        • 2011-10-01
        相关资源
        最近更新 更多