<?xml version= "1.0" encoding= "UTF-8"?>
<ehcache xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:nonamespaceschemalocation= "Http://ehcache.org/ehcache.xsd" updatecheck= "false"
<ehcache>
<!--Timetoidleseconds when the cache is idle for n seconds and then destroyed-
<!--Timetoliveseconds when the cache is alive N seconds and then destroyed-
<!--
Cache configuration
Name: Cache names.
Maxelementsinmemory: Maximum number of caches.
Eternal: The object is permanently valid, but if set, timeout will not work.
Timetoidleseconds: Sets the allowable idle time (in seconds) for an object before it expires. An optional property is used only if the Eternal=false object is not permanently valid, and the default value is 0, which means that the idle time is infinite.
Timetoliveseconds: Sets the time (in seconds) that an object is allowed to survive before it expires. The maximum time is between the creation time and the expiration time. Used only when the Eternal=false object is not permanently valid, the default is 0, which means that the object survives indefinitely.
Overflowtodisk: When the number of objects in memory reaches Maxelementsinmemory, Ehcache writes the object to disk.
DISKSPOOLBUFFERSIZEMB: This parameter sets the buffer size of the Diskstore (disk cache). The default is 30MB. Each cache should have its own buffer.
Maxelementsondisk: Maximum number of hard disk caches.
Diskpersistent: Whether to cache VM Restart period data Whether The disk store persists between restarts of the virtual machine. The default value is False.
Diskexpirythreadintervalseconds: Disk failed thread run time interval, default is 120 seconds.
Memorystoreevictionpolicy: When the maxelementsinmemory limit is reached, Ehcache will clean up the memory according to the specified policy. The default policy is LRU (least recently used). You can set it to FIFO (first in, out) or LFU (less used).
Clearonflush: If the maximum amount of memory is cleared.
<DiskstorePath= "Java.io.tmpdir" /> <Defaultcachemaxelementsinmemory= "$"Eternal= "false"Timetoidleseconds= "+"Timetoliveseconds= "$"Overflowtodisk= "true" /> <Cachename= "com. Menu "maxelementsinmemory= "Max"Eternal= "false"Timetoliveseconds= "36000"Timetoidleseconds= "3600"Overflowtodisk= "true"/> </Ehcache>
Ehcacheutil Tool class use:
1 Public classEhcacheutil {2 3 Private Static FinalString Path = "/ehcache.xml"; 4 5 PrivateURL url; 6 7 PrivateCacheManager Manager; 8 9 Private StaticEhcacheutil EhCache; Ten One Privateehcacheutil (String path) { AURL =getclass (). getresource (path); -Manager =cachemanager.create (URL); - } the - Public Staticehcacheutil getinstance () { - if(ehcache==NULL) { -Ehcache=Newehcacheutil (path); + } - returnEhCache; + } A at Public voidput (string cachename, String key, Object value) { -Cache cache =Manager.getcache (CacheName); -Element element =NewElement (key, value); - cache.put (Element); - } - in PublicObject Get (String cachename, String key) { -Cache cache =Manager.getcache (CacheName); toElement element =Cache.get (key); + returnelement = =NULL?NULL: Element.getobjectvalue (); - } the * PublicCache Get (String cachename) { $ returnManager.getcache (CacheName); Panax Notoginseng } - the Public voidRemove (string cachename, String key) { +Cache cache =Manager.getcache (CacheName); A Cache.remove (key); the } + -}
Ehcache configuration detailed and CacheManager use