Introduction to ehcache.xml in the Java web project

  • 2020-04-01 01:36:02
  • OfStack


<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false"
    monitoring="autodetect" dynamicConfig="true">
    <diskStore path="java.io.tmpdir" />

    <defaultCache maxElementsInMemory="10000" eternal="true"
        overflowToDisk="true"
        maxElementsOnDisk="10000000" diskPersistent="false"
        diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />

</ehcache>

Name: cache name.
MaxElementsInMemory: maximum number of caches.
Eternal: whether the object is permanent or not, timeout will not work once it is set.
TimeToIdleSeconds: the allowed idle time (seconds) of an object before it expires. Optional attribute when eternal=false, the default value is 0, which means infinite idle time.
Timetolivesecond: object survival time (seconds) before expiration. Maximum time is between creation time and expiration time. Used when eternal=false, default is 0, which means infinite object lifetime.
OverflowToDisk: Ehcache writes objects to disk when the number of objects in memory reaches maxElementsInMemory.
DiskSpoolBufferSizeMB: this parameter sets the size of the DiskStore cache. The default is 30MB. Each Cache should have its own buffer.
MaxElementsOnDisk: the maximum number of hard disk caches.
DiskPersistent: whether to cache virtual machine restart data, the default value is false.
DiskExpiryThreadIntervalSeconds: disk failure thread running time interval, the default is 120 seconds.
MemoryStoreEvictionPolicy: when maxElementsInMemory limit is reached, Ehcache will be based on the specified strategies to clear the memory. The default policy is LRU (least recently used). You can set it to FIFO (first in first out) or LFU (less used).
ClearOnFlush: cleared or not cleared when the amount of memory is at its maximum.

< DiskStore> Means that when the number of objects in the memory cache exceeds the number of memory caches set by the class, the cache object is written to the hard disk. Path = "java.io.tmpdir" means that the data is written to this directory. The java.io.tmpdir directory is generated at run time based on a relative path.
< DefaultCache> Represents setting the default data expiration policy for the cache.
< Cache> Represents setting a data expiration policy with a specific named cache.


Related articles: