Java Reference
In-Depth Information
The <flushOnExecute> tag has a single attribute, statement , and allows for a cache
flush to be triggered upon the execution of a particular mapped statement. This
is useful when you have results that should be updated when a change is made to
the underlying database. For example, if you have a cache containing a list of Cat-
egories, you could use <flushOnExecute> to flush the cache whenever a new Cate-
gory is inserted.
As stated earlier, the cache will be entirely flushed, and therefore you should
take care to avoid creating mapped statement flushing dependencies with con-
stantly changing data. This could effectively render your cache useless because of
the high rate of flushing and populating the cache. Listing 9.2 defines a cache
model and shows an example of how to use the <flushOnExecute> tag to invali-
date the cache when new data is added to the database.
Listing 9.2
flushOnExecute caching example
<sqlMap namespace="Category">
<cacheModel id="categoryCache" type="MEMORY">
<flushOnExecute statement="Category.insert"/>
id="getCategory" parameterClass="Category"
resultClass="Category" cacheModel="categoryCache">
FROM Category
WHERE parentCategoryId=#categoryId#
<insert id="insert" parameterClass="Category" >
To use the <flushOnExecute> tag, you need to specify the statement name, using
the statement attribute, which should trigger the cache flush. If the statement is
contained within a sqlMap that uses a namespace attribute, you must specify the full
Search WWH ::

Custom Search