MyBatis Add Ehcache Supported methods _java

Source: Internet
Author: User

1.Mybatis Default Cache configuration

MyBatis contains a very powerful query caching feature that can be easily configured and customized.

MyBatis cache contains global cache and local cache, the global cache can speak the parameters of the setting property of the main configuration file cacheenabled set to True (OK, default to True), local level two cache is not open by default, to turn on level two cache, You need to add a row to your SQL mapping file:<cache/>

Eviction (recycle policy) defaults to LRU. Selectable items have Fifo,soft,weak

The Flushinterval (refresh interval) can be set to any positive integer, and they represent a reasonable millisecond-form time period. The default is not set, that is, there is no refresh interval, and the cache refreshes only when the statement is invoked.

The size (number of references) can be set to any positive integer, remembering the number of objects you cache and the amount of available memory resources in your running environment. The default value is 1024.

The readOnly (read-only) property can be set to TRUE or false. A read-only cache returns the same instance of the cached object to all callers. Therefore, these objects cannot be modified. This provides a very important performance advantage. A writable cache returns a copy of the cached object (via serialization). This is slower, but safe, so the default is false.

2.Mybatis Add Ehcache

MyBatis Add Third-party Cache component support You only need to add a row to the SQL mapping file:

<cache type= "Org.mybatis.caches.ehcache.EhcacheCache"/>

Of course, you can choose to configure their own properties, you can choose the configuration <cache> of the child properties <property> to set specific parameters, you can also configure the class path under the Ehcache.xml to complete the configuration;

The configured properties are the same as the hibernate configuration Ehcache, and you can view my previous blog.

Of course, if you need to log, you can use

<cache type= "Org.mybatis.caches.ehcache.LoggingEhcache"/>
instead of <cache type= " Org.mybatis.caches.ehcache.EhcacheCache "/>

The above is a small set to introduce the MyBatis add Ehcache support method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.