ehcache后写行为 [英] ehcache write-behind behaviour

查看:72
本文介绍了ehcache后写行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using an EhCache based cacheWriter for write-behind cache implementation.

这是配置:

<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

after I do a cache.putWithWriter

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

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

another thread tends to read from cache with 'key'

观察:


  • 如果< 2s然后得到旧值

  • 如果> 2s然后得到更新后的值(newvalue)

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

It seems that cache is updated with 'key':newvalue only after write to datastore.


  • Q1。这是预期的行为对于后写?

  • 第二季度。是否有任何方法可以在'putWithWriter'调用完成
    之后立即使用'key':newvalue更新缓存?
    落后。

来自文档,似乎暗示了后者。

From the documentation, it seems that the later is what is implied.

推荐答案

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

This was a naive error on my side, the code calling the @Cacheble method was from the same spring service.

Spring

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

I refactored the cache enabled code out and it works as expected.

这篇关于ehcache后写行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆