When you filter a collection in a JSP, you can cache the filtered results so that future executions of that page need not run the collection filter to produce an identical result set. A filter that uses caching attempts to reuse content cached by a previous invocation that filtered an identical collection. When no cached content can be reused, the filter executes and saves its resultant collection to the cache.
To enable caching, you need to set five properties. For example, to cache content from StartEndDateFilter
, the following properties require these values:
StartEndDateFilter.cacheEnabled
=true
StartEndDateFilter.cache=
/atg/collections/filter/FilterCache
Note that this property can be set to any
Cache
component designed to work with collection filters.FilterCache
.cacheAdapter
=/atg/collections/filter/FilterCacheAdapter
StartEndDateFilterDroplet.consultCache=true
StartEndDateFilterDroplet.updateCache=true
Note: The values described in this list are the default settings for the StartEndDateFilter
implementation.
FilterCache
is a component of class atg.service.cache.Cache
designed to handle caching for collection filtering components. You can use FilterCache
to configure the caching settings.
FilterCache
has a Map object that uses a key (CollectionCacheKey
) to describe the filtering conditions and a value to hold the filtered results. Specifically, the CollectionCacheKey
is an object that consists of:
A reference to the collection filtering component
A unique string that represents the unfiltered collection identifier key. All references to a specific collection should use the same key. When you use a collection filtering servlet bean, you specify this key as an input parameter.
A context object created by the collection filter to hold context criteria used by a filter instance. For example, a
Date
context object holding the current day’s date is used by theStartEndDateFilter
to determine whether a collection of objects are active on a specific day. Not all collection filtering components have context objects.
Here’s an example of how caching could work in the StartEndDateFilter
. The first call to a JSP that uses the StartEndDateFilterDroplet
servlet bean relies on StartEndDateFilter
to generate a collection of active objects. When caching is enabled, FilterCache
saves the following information in the Map key: the StartEndDateFilter
component, the catid-53009-curtains
string, and a Date
object that specifies the date the filter was executed. The “active” objects, those being the objects that remain after filtering, are saved to the Map as a value.
Subsequent renderings of that JSP will cause the system to compare the cached CacheCollectionKey
key to the newly generated one. When the keys match, the filter returns the cached collection. By default, a cache is flushed once a day, which is appropriate for the StartEndDateFilter
since the cached content it generates is only relevant for one day.