InfoCenter Home >
6: Administer applications >
6.6: Tools and resources quick reference >
6.6.0: About user assistance >
6.6.0.4: Overview of editing property files by hand >
6.6.0.4.1: Dynamic caching of Servlets and JSPs >
6.6.0.4.1.3: Removing entries from the cache
6.6.0.4.1.3: Removing entries from the cache
Once you decide which servlets to cache, you must build unique entries for different requests.
You must also remove entries from the cache when necessary. You can remove entries
using the servletcache.xml file or by writing your own class to handle invalidation.
The cache removes entries in three circumstances:
- One of the cache's invalidation methods was called inside the servlet code.
(See the programming documentation for more information on cache invalidation methods.)
- The timeout for the entry expired.
- The cache is full and a new entry must replace an old one.
In the first case, removing the entry is done programmatically inside an application. In the other
cases, entry invalidations are configured with the <timeout> and <priority> tags.
Both tags are located in the servletcache.xml file.
- Timeout determines when an entry is invalidated. If the <timeout> element
is not present, then the <servlet> stanza that contains it, is invalidated and will not be
cached.
The format of the <timeout> element is:
<timeout seconds="time_in_cache"/>
The variable, time_in_cache, is the length of time in seconds that indicates when an entry,
after it is created, should be removed from the cache. This value is required. If this value is
zero or a negative number, the entry will not timeout and can only be removed when the cache is full
or programmatically, from within an application.
If the time_in_cache is a positive value, the timeout is added to the current time
to determine when the entry will be invalidated. When that time occurs, if the entry is still in the
cache, the cache will force its invalidation.
- Priority determines how long an entry stays in the cache.
The format of the <priority> element is:
<priority val="priority"/>
The variable, priority, is a zero or positive integer designating the length of time an
entry stays in the cache before being eligible for removal. If this element is not present,
then the default_priority, defined in the <priority> element in the dynacache.xml file,
is used.
Note: the default_priority is an integer that defines the default priority for cacheable
servlets defined in the servletcache.xml file. The recommended value for
priority is 1.
Priority is an extension of the Least Recently Used (LRU)
caching algorithm. It represents the number of cycles through the LRU algorithm an entry is guaranteed
to stay in the cache. On each cycle of the algorithm, the priority of an entry is decremented.
Once it reaches zero, the entry is eligible for invalidation. If an entry is requested while in the cache,
its priority is reset to the priority value.
In summary, a higher priority provides a longer availability for an entry. Frequently
requested entries stay in in the cache longer. But regardles of the priority value and number of requests,
an entry will be invalidated when <timeout> occurs.
Performance considerations
In a high volume application where space in the cache is at a premium, administrators should consider
increasing the priority of a servlet or JSP under these conditions:
- when it is difficult to calculate the output of the servlet or JSP
- when the servlet or JSP is executed more often than average.
Note: Priority values should be low, as higher values will not
yield much improvement, but will use extra LRU cycles. Therefore declaring a
servlet with priority 3 and another with priority 4 generates the same invalidation behavior
as servlets declared with priority 1 and 2, only marginally slower. When dealing with caches with
thousands of entries, that slowdown becomes significant.
Use timeout to guarantee the validity of an entry.
Use priority to rank the relative importance of one entry to other
entries. Giving all entries equal priority results in a standard LRU cache that increases
performance significantly. You can tailor the cache's operation using the priority variable.
|
|