Store to Cache Assertion

The Store to Cache Assertion is used to store messages or a string from a target message to a cache store of your choice. You can then use the to retrieve the cached contents. This reduces the load on back-end services and potentially improve response times.
gateway90
The
Store to Cache Assertion
is used to store messages or a string from a target message to a cache store of your choice. You can then use the Look Up in Cache Assertion to retrieve the cached contents. This reduces the load on back-end services and potentially improve response times.
In policy logic, this assertion always succeeds. If the assertion encounters problems creating or updating a cache, it is reported in the system audit log, but the assertion does not fail.
All cache entries are deleted when a Gateway node shuts down.
To learn about selecting the target message for this assertion, see Select a Target Message.
The cache is stored at the node level and is not shared between Gateway nodes. 
Policy Example
The Store to Cache assertion is normally paired with the At Least One Assertion Must Evaluate to True Assertion. The Store to Cache assertion should follow immediately afterward. The following policy fragment is an example:
[Not shown: XPath to extract clientCountry and SKU from request] Set variable "cachekey" to "Cache01-${request.url}-${request.soap.operation}-${clientCountry}-${SKU}" At Least One Assertion Must Evaluate to True Response: Look Up in Cache with key "${cachekey}" All Assertions Must Evaluate to True ? Route via HTTP to URL http://backend/anydestination Response: Store to Cache with key "${cachekey}"
In this example, the Gateway attempts to look up
${cachekey}
in the cache first. If it is successful, the entry retrieved from the cache is used for subsequent processing, sparing the back-end service from needing to respond to the request. If
${cachekey}
is not found in the cache, the request is then routed to the back-end service and the response is stored into cache.
Note that the Store to Cache assertion should follow the routing assertion.
Best Practices
It is important to note that the Store to Cache assertion maintains exactly one
Max entry age
per
Cache ID
. If the Max entry age is changed within the policy, any cached entry is discarded and the cache begins anew with the new value. For example the first Store to Cache assertion has these values:
Cache ID:
myCacheID
Cache entry key:
mykey
Max entry age:
300
The cache entry
mykey
will be cached for 300 seconds. A second Store to Cache assertion later in the policy has these values:
Cache ID:
myCacheID
Cache entry key:
myNewkey
Max entry age:
600
Since the same Cache ID is used, but with different max entry age values, the original entry key
mykey
is discarded and replaced by
myNewkey
(if the max entry ages matched, then both entry keys are retained). This may cause your caching strategy to not work as expected.
The best practice is to always use the same Max entry age per Cache ID. One way to do this is to use context variable instead of hard values:
  • Cache ID:
    ${cacheID}${lifetime}
  • Max entry age:
    ${lifetime}
This technique ensures that if the value of "${lifetime}" changes, it will result in a new corresponding Cache ID.
Using the Assertion
  1. Do one of the following:
    • To add the assertion to the Policy Development window, see Add an Assertion.
    • To change the configuration of an existing assertion, proceed to step 2 below.
  2. Right-click
    Store to Cache
    in the policy window and select
    Cache Storage Properties
    or double-click the assertion in the policy window. The assertion properties are displayed. 
  3. Configure the dialog as follows:
    Field
    Description
    Cache ID
    Enter a label to identify the cache store to use. If no cache store exists with that label, a new cache store is created.
    The cache identifier is used in the Look Up in Cache Assertion to look up entries in the corresponding cache store.
    Cache entry key
    Cached entries are identified within a cache store by a unique cache entry key. This key is used by the Look Up in Cache Assertion to look up entries and retrieve them from a cache store.
    Specify the key or reference a context variable that will contain the key.
    The cache entry key is configured for a group of related cache "store" and "lookup" assertions and should normally be the same expression.
    Maximum entries
    Enter the maximum number of cached entries that the store can hold. When this maximum is reached, each new item will replace the oldest one in the store. You may reference context variables.
    The default is
    10
    .
    Maximum entry age
    Enter the maximum age (in seconds) of items in the cache before they are discarded. You may reference context variables.
    The default is
    300
    seconds.
    Maximum entry size
    Enter the maximum size (in bytes) of the items to cache. The default is
    10000
    bytes.
    Do not cache SOAP faults
    This check box determines whether SOAP fault responses are cached:
    • Select this check box to exclude SOAP faults from being cached. This may help prevent the cache from being filled too quickly, especially if many SOAP faults are generated.
    • Clear this check box to include SOAP faults in the cache. Note that this will cause a SOAP fault to always be returned until the cached entry expires, even when the SOAP fault condition no longer occurs.  
  4. Click [
    OK
    ].