MyBatis Cache Settings

Source: Internet
Author: User
Tags time in milliseconds
Open cache:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace= "Com.shop.mapper.ArticleListMapper" >
<cache eviction= "LRU" flushinterval= "60000" size= "1024" readonly= "false"/>


Description
The eviction is the cache elimination algorithm, the optional value has "LRU", "FIFO", "SOFT", "WEAK", the default value is LRU


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


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


ReadOnly is read-only, if true, all the same SQL statements return the same object (which can help improve performance but may not be secure when you manipulate the same data concurrently), and if set to False, the same SQL, followed by the cache clone copy.





Precautions:


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


<select id= "GetOrder" parametertype= "int" resulttype= "Torder" usecache= "false" >
...
</select>
Usecache= "False" indicates that the SELECT statement does not use caching (even if the XML's first global cache is enabled)


By default, if the cache is turned on globally, the associated cache entry is automatically refreshed when the Insert/update/delete succeeds, but one particular note: When MyBatis and hibernate are mixed, because MyBatis is not related to the hibernate cache , if you use MyBatis to do a select query, use Hibernate to do insert/update/delete,hibernate changes to the data, and does not refresh the MyBatis cache.

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.