从文件系统或磁盘路径读取缓存数据 [英] Read Cache Data from File system or diskpath

查看:101
本文介绍了从文件系统或磁盘路径读取缓存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果启用了 overflowToDisk 并配置了磁盘路径,则如果在内存中未找到数据,则应该自动从 diskpath 搜索吗?

If overflowToDisk is enabled and Disk path is configured, then if data is not found in the memory should it automatically search from diskpath?

请参考提到的配置

何时在EHCACHE中激活了OverFlowToDisk?

我的案子

1)在应用程序启动前从数据库缓存预热

1) Cache warm up from DB before application start

2)通过装载程序实现从数据库装载数据

2) Load data from DB with loader implementation

3)最初,DB有2000个数据。因此,我们的内存(ABC_007)中有1000个,而磁盘中有1000个。

3) Initially DB has 2000 data. So we have 1000 in memory (ABC_007) rest 1000 we have in the DISK.

这对吗?

 <cache name="ABC_007"
           maxElementsInMemory="1000"
           maxElementsOnDisk="10000"
           overflowToDisk="true"
           timeToIdleSeconds="..."
           timeToLiveSeconds="...">
    </cache>

如果我搜索的数据不在 ABC_007 ,它将从DISKPATH检索。我对吗?

If I search for data which is not in ABC_007, it will be retrieved from DISKPATH. Am I right on this one?

现在,如果我实现了 Cache read through功能,即如果Cache中的数据不可用(包括磁盘路径),我应该在数据库中搜索。

Now, if I implement Cache read through functionality that is if the data is not available in Cache (including diskpath), I should search in the DB.

现在我找到了数据。它会重新填充缓存吗?

Now I find the Data. Does it repopulate the Cache?

如果ABC_007仍包含1000个元素。它将存储在哪里? ABC_007 还是磁盘?

If ABC_007 still consists 1000 elements. Where it will be stored? ABC_007 or disk?

请更正我的理解。

例如参考示例代码

Cache cache = manager.getCache("ABC_007");

Element element = null;

String key = null;

for (int i=0 ; i<2000 ; i++) {

key =  "keyInCache" + i ;

element = new Element (key , "value1");
cache.put(element);

}

现在,当我越过1000时,按照配置,1001到2000个元素将存储在磁盘中。

Now when i cross 1000 then as per configuration , 1001 to 2000 elements will be stored in disk .

 <cache name="ABC_007"
           maxElementsInMemory="1000"
           maxElementsOnDisk="10000"
           overflowToDisk="true"
           timeToIdleSeconds="..."
           timeToLiveSeconds="...">







现在我想要

AM I RIGHT ?

Now I want the Value for the

Key = keyInCache1700

element = cache.get(key);

从哪里获得价值?

我的理解-由于 ABC_007缓存具有maxElementsInMemory = 1000 ,这意味着它最多可以存储1000个键值内存中的值和键 keyInCache1700 的值将从磁盘中检索...

My understanding - as ABC_007 cache has maxElementsInMemory="1000" , that means it can srore upto 1000 key value in memory and value for the key keyInCache1700 will be retrieved from the Disk ...

我正确吗?

推荐答案

答案取决于您的Ehcache版本。

The answer depends on your version of Ehcache.

与Ehcache 2.6相比,存储模型不再是溢出模型,而是分层模型。
在分层存储模型中,所有数据将始终出现在最低层中。
项目将根据其热度较高层中出现。

As of Ehcache 2.6, the storage model is no longer an overflow one but a tiered one. In the tiered storage model, all data will always be present in the lowest tier. Items will be present in the higher tiers based on their hotness.

可能的开放层源Ehcache是​​:

Possible tiers for open source Ehcache are:


  • JVM堆上的堆上

  • 在磁盘上是最低的

按定义,高层比较低层具有更低的延迟,但容量较低。

By definition high tiers have lower latency but less capacity than lower tiers.

因此,对于配置了 overflowToDisk 的缓存,所有数据将始终位于磁盘层内部。它将密钥存储在内存中,并将数据存储在磁盘上。

So for a cache configured with overflowToDisk, all the data will always be inside the disk tier. It will store the key in memory and the data on disk.

在高速缓存中查找条目时,层级从最高到最低。
在您的示例中,将按以下方式检索数据:

When looking for an entry inside the cache, the tiers are considered from highest to lowest. In your example, the data will be retrieved as follows:


  1. 在内存中搜索

    • 如果找到,将其退回


  • 如果找到,则添加到内存层(热数据)并返回它。这可能会导致从内存中逐出另一个条目


  • 找到后,将其添加到缓存中并返回

这篇关于从文件系统或磁盘路径读取缓存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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