2010-09-24 26 views
2

[Avatar] 2010-09-23 18:20:41 IST 我對ehcache有以下配置。ehcache memorystoresize和diskstoresize

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

的maxElementsInMemoryStore和maxElementsOnDiskStore被設置爲100。我已經把在高速緩存150層的元件。當我查詢MemoryStoreSize和DiskStoreSize我得到138和15.我無法理解返回的大小。有人可以解釋爲什麼這樣嗎?

回答

0

有些條目既可以在內存中,也可以在磁盤上,所以添加它們不會給你總數。

+0

但是,這並不能解釋爲什麼在內存138元,當配置狀態'maxElementsInMemory =「100」' – BungleFeet 2011-04-20 11:09:16

1

我找到了原因爲MemoryStoreSize > maxElementsInMemoryhere。當超過MemoryStore的大小時,對put()的進一步調用將導致多餘的元素被推送到溢出(磁盤緩衝)隊列,該隊列使用工作線程異步刷新到磁盤。默認情況下,磁盤緩衝區隊列爲300MB,並且只有在滿時(或者在關機時,如果緩存持久存在)纔會被刷新。

獲取MemoryStoreSize的調用返回MemoryStore和磁盤後臺隊列中元素的總和。

一些元素可以在隊列中,上盤在同一時間,這解釋了爲什麼兩個數字總和不等於150