Given following cache configuration (ehcache-core 2.6.0)
<ehcache>
<cache name="myTestCache"
maxBytesLocalHeap="10M"
maxBytesLocalDisk="100M"
eternal="true"
memoryStoreEvictionPolicy="LRU"
statistics="true">
<persistence
strategy="localTempSwap"
/>
<sizeOfPolicy
maxDepth="1000000"
/>
</cache>
</ehcache>
I tried to put object with approx. 4MB size (meassured by ehcache itself) to cache, but it gets rejected (not cached, no exception is thrown) with put failed to add on heap message logged on DEBUG level.
So I increased maxBytesLocalHeap to 50M and now my object is succesfully cached with put added 34355928 on heap mesage logged.
So I am wondering, why ehcache sizeOf engine says object size is 4MB but failes to put it into 10MB cache, more than double the size it needs? I have also got calculateInMemorySize from cache indicating its size (I think this one is serialized) is really about those 4MB.
Also when this object is put in memory, ehcache logs
fault removed -34355696 from heap
fault added 5973558 on disk
Considering this is the first object in cache, why does it store only 0,7 MB to disk? I have read about tiered memory model, but this is like it stores only part of the object from heap to disk.
After this operation, statistics now show that
calculateInMemorySize = 35135952
calculateOnDiskSize = 5973558
Is this operation correct? Is there any explanation for this behaviour?