MyBatis using Oscache and Ehcache to implement level two caching

Source: Internet
Author: User
Tags zip
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

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.