The MEMORY cache type has only one property: reference-type , which specifies
the unique ID that will be referenced by query mapped statements that want to
use the cache model's configured cache.
Listing 9.4 shows a simple MEMORY cache model that uses weak references to
hold cached data for no more than 24 hours, and is flushed whenever the insert,
update, or delete mapped statement is executed.
Sample MEMORY cacheModel
<cacheModel id="categoryCache" type="MEMORY">
<property name="reference-type" value="WEAK"/>
The MEMORY cache type is a simple but effective way to cache the data in your
The LRU cache model type uses a least recently used strategy to manage the cache.
The internals to this cache determine which objects are accessed least recently
and discard them when size limits are exceeded. The discarding of cache objects
only occurs when the cache exceeds the size-limit constraint. The size limit
defines the number of objects that can be contained within the cache. Avoid plac-
ing large memory objects into this type of cache and thus running out of memory.
The LRU cache is a great fit for managing a cache based on popular access to
particular objects. Often this kind of caching strategy is used in applications that
need to cache objects used for paged results or keyed search results.
The only property that can be specified for the LRU cache type when using the
<property> tag is size , which specifies the maximum number of objects that can
be stored in the cache.
Listing 9.5 shows a simple LRU cache model that keeps the last 200 cached
objects in memory for up to 24 hours and also flushes the cache whenever the
insert, update, or delete mapped statement is called.
Sample LRU cacheModel
<cacheModel id="categoryCache" type="LRU">