curl -i "http://$PROXY_IP/echo" \
--no-progress-meter --fail-with-body You should see the following header:
X-Cache-Status: MissApply the proxy-cache plugin using the KongPlugin CRD.
This page is part of the Get started with Kong Operator and Konnect CRDs series.
Complete the previous page, Create a Service and Route before completing this page.
proxy-cache pluginUse the KongPlugin CRD to enable proxy caching on a KongService. The following example:
200 OK responsesGET and HEAD requeststext/plain content typeecho '
kind: KongPlugin
apiVersion: configuration.konghq.com/v1
metadata:
name: proxy-cache-all-endpoints
namespace: kong
plugin: proxy-cache
config:
response_code:
- 200
request_method:
- GET
- HEAD
content_type:
- text/plain; charset=utf-8
cache_ttl: 300
strategy: memory
' | kubectl apply -f -KongServiceApply the plugin by annotating the KongService with its name:
kubectl annotate -n kong kongservice service konghq.com/plugins=proxy-cache-all-endpoints --overwriteSend a request to the Route and inspect the X-Cache-Status header. The first request finds nothing in the cache, so it is sent to the upstream Service and its response is cached:
curl -i "http://$PROXY_IP/echo" \
--no-progress-meter --fail-with-body You should see the following header:
X-Cache-Status: MissSend the same request again. This time the response is served from the cache:
curl -i "http://$PROXY_IP/echo" \
--no-progress-meter --fail-with-body You should see the following header:
X-Cache-Status: HitResponses stay cached for 300 seconds, as set in the cache_ttl field of the plugin configuration.