Ehcache configuration detailed and CacheManager use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.