Java Learning-mybatis Cache policy

Source: Internet
Author: User

Listen to Geek College notes

Using the MyBatis cache requires the following three steps

First, open the cache in config. mybatis

<settings>
<setting name= "cacheenabled" value= "true"/>
</settings>

Second, specify the use of caching in the mapper header

<cache readonly= "false" size= "$" flushinterval= "120000" eviction= "LRU" ></cache>

ReadOnly true to return the same object for all the same SQL statements, which can help improve performance, but may not be secure when concurrently manipulating the same data, and if set to False then the same SQL accesses the clone copy of the cache.

Size caches the number of objects, the default value of 1024.

Flushinterval cache expiration, in milliseconds (1s=1000ms), is empty by default and will never expire as long as the capacity is sufficient.

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

LRU is least recently used to remove objects that are not used for the longest time.

FIFO advanced First out.

Soft soft references, which remove objects based on the garbage collector state and soft reference rules.

Weak weak references, based on garbage collector state and weak reference rules

Third, in the specific SQL to specify the use of the cache, the default open

<select id= "GetRowCount" resulttype= "int" usecache= "true" >

Java Learning-mybatis Cache policy

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.