ehcache中詳解參數

爲了搞清楚timeToLiveSeconds和timeToIdleSeconds這兩個參數的作用有必要
shiro-ehcache.jar中ehcache.xml的解釋

<!--Default Cache configuration. These will applied to caches programmatically created through
    the CacheManager.

    The following attributes are required:

    maxElementsInMemory            - Sets the maximum number of objects that will be created in memory
    eternal                        - Sets whether elements are eternal. If eternal,  timeouts are ignored and the
                                     element is never expired.
    overflowToDisk                 - Sets whether elements can overflow to disk when the in-memory cache
                                     has reached the maxInMemory limit.

    The following attributes are optional:
    timeToIdleSeconds              - Sets the time to idle for an element before it expires.
                                     i.e. The maximum amount of time between accesses before an element expires
                                     Is only used if the element is not eternal.
                                     Optional attribute. A value of 0 means that an Element can idle for infinity.
                                     The default value is 0.
    timeToLiveSeconds              - Sets the time to live for an element before it expires.
                                     i.e. The maximum time between creation time and when an element expires.
                                     Is only used if the element is not eternal.
                                     Optional attribute. A value of 0 means that and Element can live for infinity.
                                     The default value is 0.
    diskPersistent                 - Whether the disk store persists between restarts of the Virtual Machine.
                                     The default value is false.
    diskExpiryThreadIntervalSeconds- The number of seconds between runs of the disk expiry thread. The default value
                                     is 120 seconds.
    memoryStoreEvictionPolicy      - Policy would be enforced upon reaching the maxElementsInMemory limit. Default
                                     policy is Least Recently Used (specified as LRU). Other policies available -
                                     First In First Out (specified as FIFO) and Less Frequently Used
                                     (specified as LFU)
    -->
  • maxElementsInMemory
    • 內存中最大的元素個數,如果超過最大數量,overflowToDisk決定是否存儲到磁盤上
  • eternal
    • 是否永久有效。
    • 如果eternal=true,那麼timeToLiveSeconds、timeToIdleSeconds失效。
    • 如果eternal=false,那麼timeToLiveSeconds、timeToIdleSeconds才起作用。
  • overflowToDisk
    • 當內存中達到最大元素數量?爲true則存儲到 磁盤上,否則?根據memoryStoreEvictionPolicy決定清除策略
  • timeToIdleSeconds
    • 最大空閒時間,單位爲秒,元素過期前最大的訪問間隔,0爲永久空閒,在eternal=false時,有效。
  • timeToLiveSeconds
    • 最大存活時間,單位爲秒,創建時間和失效時間的間隔,0爲永久空閒,在eternal=false時,有效。
  • diskPersistent
    • jvm重啓時,是否保留磁盤存儲塊,默認不保留
  • diskExpiryThreadIntervalSeconds
    • check磁盤塊過期的間隔時間,默認2分鐘
  • memoryStoreEvictionPolicy
    • 內存存儲清除策略,當達到最大maxElementsInMemory限制時採用的策略,有 Least Recently Used (specified as LRU)、First In First Out (specified as FIFO)、Less Frequently Used,默認是LRU
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章