Improve Performance with Proxy Caching
In this topic, you’ll learn how to use proxy caching to improve response efficiency using the Proxy Caching plugin.
If you are following the getting started workflow, make sure you have completed Protect your Services before continuing.
What is Proxy Caching?
Kong Gateway delivers fast performance through caching. The Proxy Caching plugin provides this fast performance using a reverse proxy cache implementation. It caches response entities based on the request method, configurable response code, content type, and can cache per Consumer or per API.
Cache entities are stored for a configurable period of time. When the timeout is reached, the gateway forwards the request to the Upstream, caches the result and responds from cache until the timeout. The plugin can store cached data in memory, or for improved performance, in Redis.
Why use Proxy Caching?
Use proxy caching so that Upstream services are not bogged down with repeated requests. With proxy caching, Kong Gateway can respond with cached results for better performance.
Set up the Proxy Caching plugin
Validate Proxy Caching
Let’s check that proxy caching works. You’ll need the Kong Admin API for this
Access the /mock route using the Admin API and note the response headers:
In particular, pay close attention to the values of
HTTP/1.1 200 OK
Next, access the /mock route one more time.
This time, notice the differences in the values of
X-Kong-Upstream-Latency. Cache status is a
hit, which means Kong Gateway is responding to the request directly from cache instead of proxying the request to the Upstream service.
Further, notice the minimal latency in the response, which allows Kong Gateway to deliver the best performance:
HTTP/1.1 200 OK
To test more rapidly, the cache can be deleted by calling the Admin API:
Summary and Next Steps
In this section, you:
- Set up the Proxy Caching plugin, then accessed the
/mock route multiple times to see caching in effect.
- Witnessed the performance differences in latency with and without caching.
Next, you’ll learn about securing services.