Ehcache cache write memory and hard disk Mechanism

Source: Internet
Author: User

Ehcache is a cache framework used to configure and manage cache. We analyze from its ehcache. xml file how it inserts data into memory and hard disk.

<?xml version="1.0" encoding="UTF-8"?><ehcache><diskStore path="java.io.tmpdir" /><defaultCache maxElementsInMemory="500" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="1200" overflowToDisk="true" /><cache name="testcache" maxElementsInMemory="150" eternal="false" timeToLiveSeconds="36000" timeToIdleSeconds="3600" overflowToDisk="true"/> </ehcache>

The above

<diskStore path="java.io.tmpdir" />
This is to configure the path for storing cached files to the hard disk. It points to a temporary file storage path of the operating system. You can obtain the path information through system. getproperty ("Java. Io. tmpdir.

Maxelementsinmemory = 500 this is the maximum number of objects configured in the memory

Overflowtodisk = "true" when it exceeds 500, it will be saved to the path configured in the hard disk.

You can write a code segment to change the number of cycles: 100,400,200 0 test. check whether there are any files under the directory:

Package COM. xxinfo. ylzcache; import Org. apache. log4j. logger; import net. SF. ehcache. cache; import net. SF. ehcache. cachemanager; import net. SF. ehcache. element; public class ehcachetest {Private Static final logger = logger. getlogger (ehcachetest. class); Private Static cache samplecache = NULL; public static void main (string [] ARGs) {Init (); test ();} Private Static void test () {logger.info (samplecache. getmemorystoreevictionpolicy (); For (INT I = 0; I <2000; I ++) {// write cache samplecache. put (new element (I, "V" + I); // print all logger.info (samplecache. getkeys (); // read the cache Element E = samplecache. get (I); logger.info (E. getvalue ();} // print the logger.info (samplecache. getstatistics (); cachemanager. getinstance (). shutdown ();} Private Static void Init () {cachemanager manager = cachemanager. create (); samplecache = manager. getcache ("testcache ");}}



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.