Cache
Temporarily stores backend responses to improve performance and reduce load.
Use the Cache policy to temporarily store backend responses so repeated requests can be served more quickly and with reduced load on the backend.
For more information on the policy parameter descriptions, see DataPower Nano Gateway documentation.
Example of an Cache policy in code view.
kind: cache
apiVersion: api.ibm.com\v1
metadata:
name: "cache-invoke"
version: 1.0
namespace: sample
spec:
inputs: #used as identifiers, are not used to produce the cached results
- message: # Use the whole message as an identifier
name: request
- messageBody: # Use the value of the specified body as an identifier
name: message-2 #is an explicit parse needed
- messageHeader: # Use the value of the specified header as an identifier
messageName: request
headerName: header-1
- variable: # Use the value of the specified variable as an identifier
name: myInVar
- custom: # Can be any jsonata expr referencing values from the context
expression: "$queryParameter('request', 'query-param-1')"
outputs: #the context variables that will be cached, the execute block must produce this values, or an error will be thrown in runtime
- message: # cache the whole message
name: response
- messageBody: # Cache the specified message body
name: response
- variable: # Cache the specified variable
name: myOutVar
- messageHeader: # Cache the specified message header
messageName: response
headerName: my-header
scope:
# (1/2) narrow scope
narrowScope : {} # wideScope
# # (2/2) wide scope
# wideScope:
# scopeId: ""
expire:
# (1/4) static
static:
seconds : 60
# # (2/4) fromMessageHeader
# fromMessageHeader:
# headerName: 'x-cache-ttl'
# messageName: 'default'
# # (3/4) fromVariable
# fromVariable:
# name: '$.cache.expire'
# # (4/4) fromCacheControl
# fromCacheControl:
# messageName: 'default'
execute:
- $ref: sample:invoke-backend-service:1.0