Ehcache: two things

Source: Internet
Author: User

Ehcache: two things
Ehcache is an open source Java distributed cache. You can use it with mybatis. First, create an ehcache. xml file in the resource folder as follows:

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <ehcache xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" 3 xsi: noNamespaceSchemaLocation = ".. /bin/ehcache. xsd "> 4 <defaultCache overflowToDisk =" true "eternal =" false "maxElementsInMemory =" 1 "/> 5 <! -- Modify the path address in the production environment --> 6 <! -- Dev --> 7 <diskStore path = "D:/cache"/> 8 <! -- Product linux --> 9 <! -- <DiskStore path = "XXX"/> --> 10 </ehcache>

Serialization is required in your own model, and serialization ID must be automatically generated (this is also done in redis)

Add the following ehcache to mapper. xml:

1 <! -- Output log --> 2 <! -- <Cache type = "org. mybatis. caches. ehcache. LoggingEhcache"/> --> 3 <! -- Do not output logs --> 4 <cache type = "org. mybatis. caches. ehcache. EhcacheCache"/>

The useCache in the select expression is true by default, and the cache will be used. If you do not need it, set it to false.

 

After testing, the first query has SQL output, and the second query does not

Cached files on Hard Disk

 

 

 

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.