Proxy cache

OpenResty Edge can also support proxy cache. If the request is a static resource, or a resource that does not update frequently, you can enable caching and it will avoid going to upstream repeatedly when it hit cached at the gateway node.

As follows, there is a general reverse proxy rule.

We edit this rule (you can also turn on the cache when you create a new one, it’s the similar way).

Enable cache.

You can see several configuration items, which usually do not need to be changed.

By default, the gateway node will only be cached according to the caching policy in the upstream response header, which means that the upstream controls whether and for how long caching is enabled on the gateway node via the response header.

We can also choose to configure:

  1. default caching, i.e. if there is no cache-related response header in the upstream response, the gateway will be cached according to the default configuration.
  2. always cache, the gateway will cache the response even if the gateway is not allowed to cache it in the upstream response.

Alternatively, we can enable:

  1. shared caching at the gateway cluster level With this feature enabled, only one copy of the same cache resource will be cached inside the same gateway cluster. This means that when a request is made for a cache resource that is not locally available, the gateway will go through the intranet to the gateway node where the cache resource is stored. This is a good choice to improve the hit rate of cached resources.

  2. Cross-Domain Caching By default, cached resources are segregated across applications, which means that by default, the cache key will contain the domain name of the current request. When cross-domain caching is enabled, the requested domain name will not be included in the cache key.

Once configured, click Save to enable caching.