add -forceCache flag to override no-store and private directives

The httpcache package is intended only to be used in private caches, so
it will cache responses marked `private` like normal.  However,
imageproxy is a shared cache, so these response should not be cached
under normal circumstances.  This change introduces a potentially
breaking change to start respecting the `private` cache directive in
responses.

This also adds a new `-forceCache` flag to ignore the `private` and
`no-store` directives, and cache all responses regardless.
This commit is contained in:
Will Norris 2025-05-01 02:26:20 -07:00
parent 8170536e41
commit 1ceba2538c
5 changed files with 104 additions and 16 deletions

View file

@ -184,15 +184,19 @@ first check an in-memory cache for an image, followed by a gcs bucket:
[tiered fashion]: https://pkg.go.dev/github.com/die-net/lrucache/twotier
#### Cache Duration
#### Override Cache Directives
By default, images are cached for the duration specified in response headers.
If an image has no cache directives, or an explicit `Cache-Control: no-cache` header,
then the response is not cached.
By default, imageproxy will respect the caching directives in response headers,
including the cache duration and explicit instructions **not** to cache the response,
such as `no-store` and `private` cache-control directives.
To override the response cache directives, set a minimum time that response should be cached for.
This will ignore `no-cache` and `no-store` directives, and will set `max-age`
to the specified value if it is greater than the original `max-age` value.
You can force imageproxy to cache responses, even if they explicitly say not to,
by passing the `-forceCache` flag. Note that this is generally not recommended.
A minimum cache duration can be set using the `-minCacheDuration` flag. This
will extend the cache duration if the response header indicates a shorter value.
If called without the `-forceCache` flag, this will have no effect on responses
with the `no-store` or `private` directives.
imageproxy -cache /tmp/imageproxy -minCacheDuration 5m