Fixes LocalResponseCache for all routes
Adds flag to know if cache has been processed by the route filter. Add global cache as fallback in case there's no configuration per route and cache is enabled. Fixes gh-2848
This commit is contained in:
@@ -2166,10 +2166,11 @@ NOTE: To enable the prometheus endpoint, add `micrometer-registry-prometheus` as
|
||||
[[local-cache-response-global-filter]]
|
||||
=== The Local Response Cache Filter
|
||||
|
||||
The `LocalResponseCache` runs if its associated property is enabled (`spring.cloud.gateway.filter.local-response-cache.enabled`) and activates a local cache for all responses that meet the following criteria:
|
||||
- The request is a bodiless GET.
|
||||
- The response has one of the following status codes: HTTP 200 (OK), HTTP 206 (Partial Content), or HTTP 301 (Moved Permanently).
|
||||
- The HTTP `Cache-Control` header allows caching (that means it does not have any of the following values: `no-store` present in the request and `no-store` or `private` present in the response).
|
||||
The `LocalResponseCache` runs if its associated property is enabled (`spring.cloud.gateway.filter.local-response-cache.enabled`) and activates a local cache using Caffeine for all responses that meet the following criteria:
|
||||
|
||||
* The request is a bodiless GET.
|
||||
* The response has one of the following status codes: HTTP 200 (OK), HTTP 206 (Partial Content), or HTTP 301 (Moved Permanently).
|
||||
* The HTTP `Cache-Control` header allows caching (that means it does not have any of the following values: `no-store` present in the request and `no-store` or `private` present in the response).
|
||||
|
||||
It accepts two configuration parameters:
|
||||
|
||||
@@ -2178,10 +2179,12 @@ It accepts two configuration parameters:
|
||||
|
||||
If none of these parameters are configured but the global filter is enabled, by default, it configures 5 minutes of time to live for the cached response.
|
||||
|
||||
This filter also implements the automatic calculation of the `max-age value in the HTTP `Cache-Control` header.
|
||||
This filter also implements the automatic calculation of the `max-age` value in the HTTP `Cache-Control` header.
|
||||
If `max-age` is present on the original response, the value is rewritten with the number of seconds set in the `timeToLive` configuration parameter.
|
||||
In subsequent calls, this value is recalculated with the number of seconds left until the response expires.
|
||||
|
||||
NOTE: To enable this feature, add `com.github.ben-manes.caffeine:caffeine` and `spring-boot-starter-cache` as project dependencies.
|
||||
|
||||
WARNING: If your project creates custom `CacheManager` beans, it will either need to be marked with `@Primary` or injected using `@Qualifier`.
|
||||
|
||||
=== Forward Routing Filter
|
||||
|
||||
Reference in New Issue
Block a user