Caching in general has broad meaning. For example, in a traditional web applica-
tion that contains presentation, service, and data access layers, it could make
sense to cache on any or all of those layers. The iBATIS cache focuses on caching
results within the persistence layer. As such, it is independent of the service or pre-
sentation layers, and is not based on object identity.
In this chapter, we will look at how to configure, optimize, and even extend the
iBATIS caching implementations.
9.1 A simple iBATIS caching example
IBATIS 's robust and simple caching mechanism is completely configuration based
and removes the burden of managing the cache directly. Before we get into when,
why, and how to use iBATIS caching, let's walk through a quick introduction. List-
ing 9.1 shows a simple cache configuration and a single mapped statement that
Basic caching example
<cacheModel id="categoryCache" type="MEMORY">
<property name="reference-type" value="WEAK"/>
In the example in listing 9.1, you can see the two major components: the cache
model and the mapped statement ( select ). The cache model defines how the
cache will store fresh results and clear stale data from the cache. Mapped state-
ments that want to use the cache just need to reference it using the cacheModel
attributes of the <select> and <procedure> tags.
In listing 9.1 the cache model specifies a cache type of MEMORY . This is a built-
in iBATIS caching that stores results into memory. This is usually the most-used
means of caching in iBATIS . Within the body of the cache model are a couple of