-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
agustafson edited this page Sep 26, 2012
·
3 revisions
In order to cascade caching for a list of items we need to create an association between an item property and a mybatis mapped statement query id. For example, the id field in Product is associated with the findProductById query.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cascading-cache-config
PUBLIC "-//mybatis.org//DTD Cascading Cache Plugin 1.0//EN"
"http://www.mybatis.com/plugin/cascading-cache-plugin.dtd">
<cascading-cache-config>
<mapped-statement namespace="domain.blog.mappers.AuthorMapper">
<cascade-query-cache incoming-query-id="selectAllAuthors">
<cascaded-query cascaded-query-id="selectAuthorById">
<cached-property property="id"/>
</cascaded-query>
<cascaded-query cascaded-query-id="findAuthorsByUsername">
<cached-property property="username" parameter-name="name"/>
</cascaded-query>
</cascade-query-cache>
</mapped-statement>
</cascading-cache-config>
In the example above we're saying:
whenever we see an incoming-query-id of selectAllAuthors
for each of the Author results
put an entry in the cache for selectAuthorById using the id of this Author
put an entry in the cache for findAuthorByUsername using the username of this Author
All you need to do is add an entry to your mybatis config file, similar to this:
<plugins>
<plugin interceptor="org.mybatis.plugin.CascadingCachePlugin">
<property name="cascading.cache.config.location" value="/config/CascadingCache-example.xml" />
</plugin>
</plugins>
where the location is somewhere on your classpath.