Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When overFlowToDisk gets activated in EHCACHE?

I have some questions on "overflowToDisk" attribute of element?

1) I read at this URL that :

overflowToDisk sets whether element can overflow to disk when the memory store has reached the maximum limit.

"Memory" above refers JVM memory allocated for Java process running EHCACHE, or is there any parameter in to specify Cache memory size?

2) When the poces running EHCACHE terminates for some reason, whether this disk gets cleared and everything in cache gets vanished?

like image 555
Vicky Avatar asked Sep 05 '10 05:09

Vicky


2 Answers

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 an open source 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.

Answer copied from this other question.

like image 79
Louis Jacomet Avatar answered Nov 07 '22 07:11

Louis Jacomet


Elements start to overflow to the disk when you have more than maxElementsInMemory of them in the memory store. The following example creates a cache that stores 1000 elements in memory, and, if you need to store more, up to 10000 on disk:

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

For the second question, have a look at the diskPersistent parameter. If it is set to true, Ehcache will keep your data stored on the disk when you stop the JVM. The following example demonstrates this:

<cache name="cacheName"
       maxElementsInMemory="1000"
       maxElementsOnDisk="10000"
       overflowToDisk="true"
       diskPersistent="true"
       timeToIdleSeconds="..."
       timeToLiveSeconds="...">
</cache>
like image 34
candiru Avatar answered Nov 07 '22 06:11

candiru