Service result cache

This policy caches service results to avoid repeated processing.

Using the Service result cache policy, you can define the elements for which the API responses are to be cached based on the criteria such as HTTP Header, XPath, Query parameters, and so on. You can also limit the values to store in the cache using a whitelist. For the elements that are stored in the cache, you can specify other parameters such as Time to Live and Maximum response payload size.

In IBM API Studio, this policy is identified by the kind CacheServiceResult.

Example of a Service result cache policy in code view.

kind: CacheServiceResult
apiVersion: api.ibm.com\v1
metadata:
    name: my-default-cache
    version: 1.0
    namespace: default
    tags:
        - cache
        - service
        - result
        - monitoring
        - policy
spec:
  condition: (${request.headers.test} equals test1) or (${request.query.test} equals test1})
  ttl: 4d
  maxSize: 32kb

For the CacheServiceResult policy kind, configure these specifications:

Code view Form view Description
Condition HTTP header and query parameters

Specifies the criteria that IBM API Studio uses to determine the payload based on the results of the cached API invocation.

Include them in the format (${request.headers.test} equals test1)or (${request.query.test} equals test1})

ttl Time to live

Specifies the lifespan of the elements in the cache after which the elements are considered to be out-of-date. The default time format is minutes if the input is a number. The time is specified in terms of days, hours, and minutes; for example, 5d 4h 1m. If you do not specify any value, the Time to Live is considered to be unlimited (does not expire). If you set the value to 0d 0h 0m, the API results are not cached.

maxSize Maximum response payload size (in KB)

Specifies the maximum payload size for the API in kilo bytes. The value -1 stands for unlimited payload size.