【发布时间】: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