I got interested in cache_handler
from the thread Increase cache entry size when using minimal cache configuration
I’ve been reading up on the example configurations but there are a few things I don’t quite understand.
First, is there a way to define maximum memory usage for the entire cache? Secondly, how can we limit the size of the objects stored in the cache, that is allow objects >n and/or <n size?
Since I couldn’t find a suitable example, I tried the Redis back-end as Redis can be configured as a ram cache with automatic eviction according to LFU or LRU. Unfortunately, there is a bug preventing keys from being stored in Redis.
What I would like to achieve is:
- Set a RAM usage limit for the cache as a whole.
- Optionally have a disk based cache for objects not in ram.
- Be able to set a maximum object size to prevent very large files from consuming the cache and evict all other objects.
My use case is primarily to cache responses from a file server (a repo mirror) that this Caddy instance is a reverse proxy for.
Would this be possible to achieve using any of the existing back-ends to the cache-handler plugin?
This is my current setup using Redis back-end.
{
# debug
auto_https off
log {
output file /var/log/caddy/caddy_main.log {
roll_disabled
}
format json
}
servers {
metrics
trusted_proxies cloudflare
}
cache {
redis {
configuration {
InitAddress 127.0.0.1:1212
SelectDB 0
Username caddy
Password <redacted>
ConnWriteTimeout 5s
}
}
}
}
mirrors.tnonline.net:443 {
tls /etc/caddy/certs/mirrors.tnonline.net_cert.pem /etc/caddy/certs/mirrors.tnonline.net_privkey.pem
log {
output file /var/log/caddy/mirrors.tnonline.net.log {
roll_disabled
}
format json
}
encode br zstd gzip
@botz {
header User-Agent *amazonbot*
}
redir @botz https://developer.amazon.com/support/amazonbot 401
respond @botz 429
#cache <-- temporarily disabled due to bug
reverse_proxy h2c://mirrors.tnonline.net:400 {
header_up Host {upstream_hostport}
}
}
I am hoping we can come up with a basic configuration example for each of the requirements.