Caching is configured using the filterId
of the cacheConfig.xml
file. As well as specifying the filterId
to cache, you must specify any repository or item descriptor related to the cached resource. The RepresentationCache
creates listeners that flush the cache when repository items that have cached representations change, such as during a deployment event or a PUT/DELETE request. Only representations of static resources, such as categories, products or SKUs are cached, so as not to create large numbers of caches.
The maximumCacheEntries
for the cache created for the filter can also be set using cacheConfig.xml
file.
The following is an example of a cache configuration:
/atg/dynamo/service/jaxrs/cache/cacheConfig.xml <?xml version="1.0" ?> <!DOCTYPE cache-configs SYSTEM "dynamosystemresource:/atg/service/jaxrs/cache/cache_config_1.0.dtd"> <cache-configs> <cache-config cacheName="products.id-Summary" maximumCacheEntries="1000"> <item-type repository="/atg/commerce/catalog/ProductCatalog" name="product"/> </cache-config> </cache-configs>
Each filterId
cache is keyed off of the URI to the resource, header values and any parameters. The RepresentationCache
component has a keyHeaders
property that allows you to specify which request headers should be keyed. Additionally, the RepresentationCache
also has an excludeParametersFromKey
property that excludes specific request parameters. For example:
enabled=true invalidatePerChange=true defaultMaxCacheEntries=1000 cacheConfigFile=/atg/dynamo/service/jaxrs/cache/cacheConfig.xml … keyHeaders=\ Accept,\ Accept-Language,\ X-OCAsset-Language excludeParametersFromKey=\ jsessionid
JSON responses are added to the cache in the CacheWriterInterceptor
after the MessageBodyWriters
have been invoked to produce the JSON. The response is cached only when the response entity is a RepresentationModel
. This avoids caching any error JSON unnecessarily. When caching is enabled, responses for a GET request are cached on the server.