Skip to main content

Caching Policy

Respond to matched incoming requests with cached content

Configuration

{
"name": "my-caching-inbound-policy",
"policyType": "caching-inbound",
"handler": {
"export": "CachingInboundPolicy",
"module": "$import(@zuplo/runtime)",
"options": {
"expirationSecondsTtl": 60,
"dangerouslyIgnoreAuthorizationHeader": false,
"headers": [
"header_used_as_part_of_cache_key"
]
}
}
}
  • name the name of your policy instance. This is used as a reference in your routes.
  • policyType the identifier of the policy. This is used by the Zuplo UI. Value should be caching-inbound.
  • handler/export The name of the exported type. Value should be CachingInboundPolicy.
  • handler/module the module containing the policy. Value should be $import(@zuplo/runtime).
  • handler/options The options for this policy:
    • cacheId
      [object Object]
    • dangerouslyIgnoreAuthorizationHeader
      [object Object]
    • headers
      [object Object]
    • expirationSecondsTtl
      [object Object]
    • statusCodes
      [object Object]

Cache-busting

If you need to support cache-busting on demand, we recommend applying a cacheId property based on an Environment Variable. Ensure all your cache policies are using a cachedId based on a variable and then change that variable (and trigger a redeploy) to clear the cache.

e.g.

{
"export": "CachingInboundPolicy",
"module": "$import(@zuplo/runtime)",
"options": {
"cachedId": "$env(CACHE_ID)", // this is reading an env var
"expirationSecondsTtl": 60,
"dangerouslyIgnoreAuthorizationHeader": false,
"headers": ["header_used_as_part_of_cache_key"]
}
}

Then you would setup an env var for this, we recommend using the current date it was set, e.g. 2023-07-05-11-57 and then simply change this value and trigger a redeploy to bust your cache.

Env Var

Read more about how policies work