In Ibatis, the framework has built-in support for Oscache, and if we want to use ehcache, we need to implement the functional mechanism of level two caching by hand.
In MyBatis, the development organization provides only some of the default level two cache implementation mechanisms, and does not have a direct built-in support for two-level caching mechanisms such as Oscache and Ehcache, but as an integrated jar package to provide a two-level cache implementation, On the official website we can find independent toolkits such as Mybatis-ehcache-1.0.1-bundle.zip,mybatis-oscache-1.0.1-bundle.zip, Ehcache and Oscache, which provide level two caching. Here, I'll take oscache. Use in MyBatis to illustrate:
1. Place the jar package involved in the Mybatis-oscache-1.0.1-bundle.zip into the classpath path
2. The configuration in the mapper file is as follows:
<mappernamespace= "Org.acme.FooMapper"
<cache type= "Org.mybatis.caches.oscache.OSCache"/>
</mapper>
3: Create a Oscache.properties property file in the SRC directory, specifying the settings for the various properties of the cache:
# Cache.path=c:\\myapp\\cache
# or *ix:
# Cache.path=/opt/myapp/cache
# Cache.path=c:\\app\\cache
# Cache.algorithm=com.opensymphony.oscache.base.algorithm.lrucache
# Cache.algorithm=com.opensymphony.oscache.base.algorithm.fifocache
# Cache.algorithm=com.opensymphony.oscache.base.algorithm.unlimitedcache
cache.capacity=1000