MyBatis 3.x Caching Cache usage

Source: Internet
Author: User

The MyBatis 3.x already supports the cache feature, and it is easy to add the following nodes to the Mappper XML file:

1 <Mappernamespace= "Com.cnblogs.yjmyzz.mybatis.mapper.OrderMapper">2 3     <Cache4         Eviction= "LRU"5 Flushinterval= "60000"6 size= "1024x768"7 readOnly= "true"8     />    9 ...Ten </Mapper>

Here are a few points to note:

Eviction is a cache culling algorithm with an optional value of "LRU", "FIFO", "SOFT", "WEAK", and the default value is LRU

Flashinterval refers to the cache expiration time, in milliseconds, 60000 is 60 seconds, the default value is empty, that is, as long as the capacity is sufficient, never expires

size refers to how many objects are cached, with a default value of 1024

If readOnly is read-only, if true, all the same SQL statements return the same object (which helps improve performance, but may not be secure when the same data is concurrently manipulated), and if set to False, the same SQL, The clone copy of the cache is accessed later.

This is the global setting, which can also have local settings on each individual SQL statement, such as:

<id= "GetOrder"  parametertype= "int"  resulttype= "Torder"  usecache= "false">        ...     </ Select >

usecache= "false" means that the SELECT statement does not use the cache (even if the XML starts with the global cache enabled)

By default, if the cache is turned on globally, the associated cache entries are automatically refreshed when Insert/update/delete succeeds, but one thing to note : When MyBatis and hibernate are mixed, Because MyBatis and hibernate cache is irrelevant, if use mybatis do select query, Hibernate do insert/update/delete,hibernate to the data modification, and will not refresh MyBatis cache.

MyBatis 3.x Caching Cache usage

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.