sillygod / cdp-cache

a caddy 2 proxy cache plugin
MIT License
119 stars 17 forks source link

allow to answer with stale cache entry in case of upstream server error #45

Closed corneliusludmann closed 3 years ago

corneliusludmann commented 3 years ago

At Gitpod, we would like to use this great plugin to use cached entries in case the upstream server answers with an HTTP status code >= 500 (server error). This is similar to the proxy_cache_use_stale option of nginx (see nginx docs).

This PR adds a new config option stale_max_age with a default of 0. If this value is > 0, this duration is added to the expiration time. That means entries are kept in the cache for this time after they have already expired. When the upstream server answers with an HTTP status code >= 500 (server error) this plugin checks whether there is still an expired (stale) entry from a previous, successful call in the cache. In that case, this stale entry is used to answer instead of the 5xx response. Otherwise, the expired entries are ignored.

We would be happy if you would accept this change and thus expand the possibilities of the use of this plugin. Please let me know if you need anything else from me.

corneliusludmann commented 3 years ago

It seems that you need to reformat it with gofmt.

Oh yes, definitely. That slipped through. It's done, @sillygod!