Reputation: 18035
[Avatar] 2010-09-23 18:20:41 IST I have the following configuration for my ehcache.
<CacheManager dynamicConfig="true" monitoring="autodetect" name="CacheManager1"
updateCheck="true"> <diskStore path="java.io.tmpdir" /> <defaultCache
clearOnFlush="true" copyOnRead="false" copyOnWrite="false" diskAccessStripes="1"
diskExpiryThreadIntervalSeconds="5" diskPersistent="true" diskSpoolBufferSizeMB="20"
eternal="true" logging="true" maxElementsInMemory="100" maxElementsOnDisk="100"
memoryStoreEvictionPolicy="LRU" name="cache1" overflowToDisk="true" statistics="true"
timeToIdleSeconds="0" timeToLiveSeconds="60" transactionalMode="off"> </defaultCache>
<cache clearOnFlush="true" copyOnRead="false" copyOnWrite="false" diskAccessStripes="1"
diskExpiryThreadIntervalSeconds="5" diskPersistent="true" diskSpoolBufferSizeMB="20"
eternal="true" logging="true" maxElementsInMemory="100" maxElementsOnDisk="100"
memoryStoreEvictionPolicy="LRU" name="cache1" overflowToDisk="true" statistics="true"
timeToIdleSeconds="0" timeToLiveSeconds="60" transactionalMode="off"> </cache>
</CacheManager>
The maxElementsInMemoryStore and maxElementsOnDiskStore are set to 100. I have put 150 elements in the cache. When i query for the MemoryStoreSize and the DiskStoreSize i get 138 and 15. I could not understand the sizes returned. Can someone please explain why is it so??
Upvotes: 2
Views: 1676
Reputation: 1810
I found the reason for MemoryStoreSize > maxElementsInMemory
here. When the size of the MemoryStore has been exceeded, further calls to put()
will cause the extra elements to be pushed to an overflow (disk spool) queue, which is flushed to disk asynchronously using a worker thread. The disk spool queue is 300MB by default, and only gets flushed when full (or at shutdown, if the cache is persistent).
The call to get MemoryStoreSize
returns the sum of the elements in the MemoryStore and in the disk spool queue.
Some elements may be in the queue and on disk at the same time, which explains why the two numbers do not sum to 150.
Upvotes: 1
Reputation: 2141
Some entries can be both in memory and on disk so adding them up will not give you the total.
Upvotes: 0