Ehcache configuration detailed and CacheManager use

Source: Internet
Author: User

<?xml version= "1.0" encoding= "UTF-8"?>
<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.

1 <DiskstorePath= "Java.io.tmpdir" />   2 <Defaultcache3   maxelementsinmemory= "$"   4 Eternal= "false"   5 Timetoidleseconds= "+"   6 Timetoliveseconds= "$"   7 Overflowtodisk= "true" />   8     <Cachename= "com. Menu "maxelementsinmemory= "Max"Eternal= "false"Timetoliveseconds= "36000"Timetoidleseconds= "3600"Overflowtodisk= "true"/>   9 </Ehcache> 

Ehcacheutil Tool class use:

1 Public class Ehcacheutil {2   3 private static final String path = "/ehcache.xml"; 4   5 private URL url; 6   7 Private CacheManager Manager; 8   9 private static Ehcacheutil EhCache; Ten    One Private Ehcacheutil (String path) { A URL = getclass (). getresource (path);  - manager = cachemanager.create (URL);  -     }   the    - Public static Ehcacheutil getinstance () { - if (ehcache== null) { - ehcache= New Ehcacheutil (path);  +         }   - return ehCache;  +     }   A    at Public void put (string cachename, String key, Object value) { - Cache cache = Manager.getcache (cachename);  - element element = new Element (key, value);  - cache.put (Element);  -     }   -    in Public Object Get (String cachename, String key) { - Cache cache = Manager.getcache (cachename);  to element element = Cache.get (key);  + return element = = null? Null:element.getObjectValue ();  -     }   the    * Public Cache Get (String cachename) { $ return Manager.getcache (CacheName); Panax Notoginseng     }   -    the Public void Remove (string cachename, String key) { + Cache cache = Manager.getcache (cachename);  A Cache.remove (key);  the     }   +    -}

Reprinted from: http://www.cnblogs.com/sunxucool/p/3159076.html

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.