<property name="size" value="200"/>
The LRU cache is quite useful for applications where different subsets of data are
used for periods of time.
The FIFO cache model uses a first in, first out strategy. The FIFO is an age-based
strategy and removes the oldest cached objects first. The discarding of cache
objects occurs only when the cache exceeds the size-limit constraint. The size limit
defines the number of objects that can be contained within the cache. Again,
avoid placing large memory-consuming objects into this type of cache and thus
running out of memory.
Since the FIFO is age based, it is good for caching objects that are more rele-
vant when initially placed into the cache. Over time the results may become less
relevant yet still be accessed. A time-based reporting application may find this type
of caching useful. If you were reporting stock prices, most inquiries would be rele-
vant in the beginning and yet decline in importance as time went on.
The only property that can be specified for the FIFO 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.6 shows a simple FIFO cache model that keeps the last 1,000 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 FIFO cacheModel
<cacheModel id="categoryCache" type="FIFO">
<property name="size" value="1000"/>
The FIFO cache is useful for applications where rolling subsets of data are used for
periods of time, like a shopping cart.