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!