问题描述
我想结合使用EhCache和内存和磁盘缓存。内存已满时,EhCache应该将 new 元素移至磁盘。例如我在ehCache内存存储区中有100个元素,并尝试将101st元素放满,如果内存已满,则将101st元素放到磁盘上而不是1st元素上。
Ehcache不再适用。自从Ehcache 2.6引入并从那时起使用的分层模型,将始终将所有映射存储到您所在的磁盘的较低层中。
原因是可预测的延迟。如果Ehcache在使用磁盘之前等待内存层已满,则可能会发现延迟增加,这可能是在应用程序最差的时间。虽然将所有映射都写入磁盘的模型为您提供了写入延迟的上限,但是对于直接在内存中可用的热值,读取可能会更快。
I would like to use EhCache in combination of memory and disk cache. EhCache should move new elements to disk when memory is full. e.g. I have 100 elements in ehCache memory store and tries to put 101st element and if memory is full then put 101st element to disk not 1st element.
Could you please let me know the cache configuration to achieve this?
Ehcache no longer works that way. The tiering model introduced in Ehcache 2.6 and used since then will always store ALL mappings into the lower tier, disk in your case.
The reason is predictable latency. If Ehcache waited for the memory tier to be full before using the disk, you would see a latency increase maybe at the worst time for your application. While the model were all mappings are written to disk gives you the upper bound for the write latency, while reads may be faster for hot value that are available in memory directly.
这篇关于如果内存存储已满,EhCache会将新元素放入磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!