Java Reference
In-Depth Information
Table 9.2
Built-in cache model types
Cache model type
This model simply stores the cached data in memory
until the garbage collector removes it.
This is a fixed size model that uses a “first in, first out”
algorithm to remove items from memory.
This is another fixed-size model that uses a “least
recently used” algorithm to remove items from memory.
This model uses the OpenSymphony (or OS) cache.
The caching implementation used is specified by adding its default keyword
( MEMORY , LRU , FIFO , and OSCACHE ) to the type attribute of the <cacheModel> tag.
Section 9.5 will discuss the four default cache implementations in detail.
It is also possible to provide your own caching by writing an implementation of
the CacheController interface and specifying its fully qualified class name in the
type attribute (see chapter 12).
The readOnly attribute
The <cacheModel> tag provides a readOnly attribute. This attribute is simply an
indicator that provides instruction to the cache model, telling it how it should
retrieve and store the cached object. Setting this attribute to true does not pre-
vent retrieved objects from having their contents altered. When specifying a cache
as read only, you tell the cache model that it is allowed to pass back a reference to
the object that exists in the cache because it is not going to be altered by the appli-
cation that is requesting it. If the readOnly attribute is set to false, this ensures that
more than one user does not retrieve the same instance of a cached reference.
The readOnly attribute works in conjunction with the serialize attribute. It is
important to understand how these two attributes work together.
The serialize attribute
The serialize attribute is used to instruct how cached objects are returned.
When serialize is set to true, each object requested from the cache is returned
as a deep copy. This means that the object you retrieve from the cache will have an
identical value but will not be the same instance. This ensures that the actual ver-
sion that is stored in the cache is never returned. It is important to call attention
to the fact that this is not serialization as most would think of it. The objects do
not get serialized to disk. This is memory-based serialization that creates deep
copies of the cached objects that are in memory.
Search WWH ::

Custom Search