Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
626 views
in Technique[技术] by (71.8m points)

caching - Read Cache Data from File system or 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?

Refer the configuration mentioned

When overFlowToDisk gets activated in EHCACHE?

My case

1) Cache warm up from DB before application start

2) Load data from DB with loader implementation

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

Is this correct?

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

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

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?

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

Please Correct my understandings.

For example refer the sample code

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);

}

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);

FROM Where I will get the Value ?

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 ...

AM I Correct ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The answer depends on your version of Ehcache.

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.

Possible tiers for open source Ehcache are:

  • On-heap that is on the JVM heap
  • On-disk which is the lowest one

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

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. Search in memory
    • If found, return it
  2. Search on disk
    • If found, add to memory tier (hot data) and return it. This can cause another entry to be evicted from memory
  3. Use your cache loader to retrieve it from DB
    • When found, add it to the cache and return it

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...