MyBatis EHCache integration - Reference Documentation

EHCache is a widely used java distributed cache for general purpose caching, Java EE and light-weight containers.

The EHCache integration is built on top of the ehcache-core and comes without any EHCache 3rd part applications. Please refeer to official EHCache documentation if you need plugins.

Users that want to use EHCache into their applications, have to download the zip bundle, decompress it and add the jars in the classpath; Apache Maven users instead can simply add in the pom.xml the following dependency:

<dependencies>
  ...
  <dependency>
    <groupId>org.mybatis.caches</groupId>
    <artifactId>mybatis-ehcache</artifactId>
    <version>1.0.1</version>
  </dependency>
  ...
</dependencies>

then, just configure it in the mapper XML

<mapper namespace="org.acme.FooMapper">
  <cache type="org.mybatis.caches.ehcache.EhcacheCache"/>
  ...
</mapper>

You can also provide values for parameters that can be modified dynamically at runtime:

<mapper namespace="org.acme.FooMapper">
  <cache type="org.mybatis.caches.ehcache.EhcacheCache"/>
    <property name="timeToIdleSeconds" value="3600"/><!--1 hour-->
    <property name="timeToLiveSeconds" value="3600"/><!--1 hour-->
    <property name="maxEntriesLocalHeap" value="1000"/>
    <property name="maxEntriesLocalDisk" value="10000000"/>
    <property name="memoryStoreEvictionPolicy" value="LRU"/>
  </cache>
  ...
</mapper>

If users need to log cache operations, they can plug the Cache logging version:

<mapper namespace="org.acme.FooMapper">
  <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
  ...
</mapper>

Users that need to configure EHCache through XML configuration file, have to put in the classpath the /ehcache.xml resource; please refeer to the official EHCache documentation to know more details.

If the /ehcache.xml resource is not found or something goes wrong while loading it, the default configuration will be used.