1.Mybatis default cache configuration
MyBatis contains a very powerful query cache feature that can be configured and customized very easily.
Mybatis cache contains global cache and local cache. The global cache can be set to true in the setting property parameter cacheEnabled (well, default is true). Local secondary cache is not enabled by default. To enable secondary cache, you need to add a line to your SQL mapping file: <cache/>
eviction (recycling policy) The default is LRU. Optional options include FIFO, SOFT, WEAK
flushInterval can be set to any positive integer, and they represent a reasonable millisecond form of time period. The default is not set, that is, there is no refresh interval, and the cache is refreshed only when the statement is called.
size (number of references) can be set to any positive integer, remember the number of objects you cache and the number of available memory resources in your running environment. The default value is 1024.
The readOnly property can be set to true or false. A read-only cache returns the same instance of the cache object to all callers. Therefore, these objects cannot be modified. This provides important performance advantages. A readable and writeable cache returns a copy of the cache object (by serialization). This will be slower, but safe, so it is false by default.
2.Mybatis adds Ehcache
Mybatis adds third-party cache component support to support only need to add one line to the sql mapping file:
<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>
Of course, you can choose to configure your own properties. You can choose to configure the subproperty of <cache> to set specific parameters, or you can configure the configuration by configuring ehcache.xml under the class path;
The configuration properties are the same as Hibernate configuration Ehcache. You can check 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 the method of adding Ehcache support to Mybatis introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!