Look Up in Cache Assertion
The Look Up in Cache assertion is used to look up an item in a cache store that was placed by the Store to Cache Assertion. If the lookup is successful, the item is placed into the message target of your choice (request, response, or context variable). If the lookup is unsuccessful, the assertion returns status code 600 ("Assertion Falsified") for cache misses or 601 ("Error in Assertion Processing") on processing errors.
gateway
The
Look Up in Cache
assertion is used to look up an item in a cache store that was placed by the Store to Cache Assertion. If the lookup is successful, the item is placed into the message target of your choice (request, response, or context variable). If the lookup is unsuccessful, the assertion returns status code 600 ("Assertion Falsified") for cache misses or 601 ("Error in Assertion Processing") on processing errors.You can optionally override the Content-Type of the cached item during lookup.
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 Look Up in Cache assertion is normally paired with the Store to Cache assertion. The "Look up" assertion should be placed before the routing assertion inside of an "At least one..." folder. The "Store" assertion should follow immediately afterward:
[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
API Gateway
will attempt 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.
Using the Assertion
- 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.
- Right-clickLook Up in Cachein the policy window and selectCache Lookup Propertiesor double-click the assertion in the policy window. The assertion properties are displayed.
- Configure the dialog as follows:SettingDescriptionCache IDSpecify the identifier for the cache to be searched. This identifier was defined in the Store to Cache assertion.Cache entry keySpecify the key to be looked up in the cache. This key should normally match the one configured in the Store to Cache assertion.Maximum acceptable ageSpecify the maximum acceptable age (in seconds) of a cached item. If an item is below this age, it will be retrieved from the cache and returned in the response. If the cached item exceeds this age, it will not be retrieved. You may reference context variables.The default is300seconds.Content-type overrideThe original Content-Type is cached and will be used in the "Look Up" message. You may override the original Content-Type if necessary, otherwise leave this field blank.
- Click [OK].