Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Cache configuration lost on reload

未关闭
#134 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
go
领域
backend

调研方向

使用所示的 Caddyfile 启动 Caddy、填充 Nuts 缓存,然后运行 caddy reload --config /etc/caddy/Caddyfile,以复现该问题。跟踪缓存处理器的 reload 和 Nuts 存储初始化,重点关注 reload 为何会选择默认存储。完成的标志是,配置的 /tmp/nuts-configuration 存储在 reload 后仍保持活动状态,不再出现默认存储警告,并且缓存的请求仍然报告命中。

由索引模型根据 Issue 内容生成。

描述

Hello,

whenever I reload Caddy, either automatically by using the -w flag of caddy run or by running caddy reload --config /etc/caddy/Caddyfile, the cache seems to loose its configuration.

When first starting caddy, everything looks fine:

{"level":"info","ts":1764181169.6021588,"msg":"maxprocs: Leaving GOMAXPROCS=6: CPU quota undefined"}
{"level":"info","ts":1764181169.6022556,"msg":"GOMEMLIMIT is updated","package":"github.com/KimMachineGun/automemlimit/memlimit","GOMEMLIMIT":15010014412,"previous":9223372036854775807}
{"level":"info","ts":1764181169.602276,"msg":"using config from file","file":"/etc/caddy/Caddyfile"}
{"level":"info","ts":1764181169.603072,"msg":"adapted config to JSON","adapter":"caddyfile"}
{"level":"warn","ts":1764181169.6030767,"msg":"Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies","adapter":"caddyfile","file":"/etc/caddy/Caddyfile","line":4}
{"level":"info","ts":1764181169.603848,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
{"level":"info","ts":1764181169.604289,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0001b2180"}
{"level":"info","ts":1764181169.6060863,"logger":"http.handlers.cache","msg":"Set backend timeout to 10s"}
{"level":"info","ts":1764181169.6061225,"logger":"http.handlers.cache","msg":"Set cache timeout to 10ms"}
{"level":"info","ts":1764181169.606124,"logger":"http.handlers.cache","msg":"Souin configuration is now loaded."}
{"level":"warn","ts":1764181169.6062827,"logger":"http","msg":"HTTP/2 skipped because it requires TLS","network":"tcp","addr":":4443"}
{"level":"warn","ts":1764181169.6062887,"logger":"http","msg":"HTTP/3 skipped because it requires TLS","network":"tcp","addr":":4443"}
{"level":"info","ts":1764181169.60629,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
{"level":"info","ts":1764181169.6107454,"msg":"autosaved config (load with --resume flag)","file":"/root/.config/caddy/autosave.json"}
{"level":"info","ts":1764181169.6107526,"msg":"serving initial configuration"}
{"level":"info","ts":1764181169.6152978,"logger":"tls","msg":"cleaning storage unit","storage":"FileStorage:/root/.local/share/caddy"}
{"level":"info","ts":1764181169.6198232,"logger":"tls","msg":"finished cleaning storage units"}

I can verify that caching works:

$ curl -i localhost:4443/nuts-configuration
HTTP/1.1 200 OK
Cache-Control:
Cache-Status: Souin; fwd=uri-miss; stored; key=GET-http-localhost:4443-/nuts-configuration
Content-Length: 10
Content-Type: text/plain; charset=utf-8
Server: Caddy
Date: Wed, 26 Nov 2025 18:25:42 GMT
Hello nuts

$ curl -i localhost:4443/nuts-configuration
HTTP/1.1 200 OK
Age: 2
Cache-Control:
Cache-Status: Souin; hit; ttl=1498; key=GET-http-localhost:4443-/nuts-configuration; detail=NUTS
Content-Length: 10
Content-Type: text/plain; charset=utf-8
Date: Wed, 26 Nov 2025 18:25:42 GMT
Server: Caddy
Hello nuts

$ curl -i localhost:4443/nuts-configuration
HTTP/1.1 200 OK
Age: 4
Cache-Control:
Cache-Status: Souin; hit; ttl=1496; key=GET-http-localhost:4443-/nuts-configuration; detail=NUTS
Content-Length: 10
Content-Type: text/plain; charset=utf-8
Date: Wed, 26 Nov 2025 18:25:42 GMT
Server: Caddy
Hello nuts

Then after editing a trivial thing, e.g. appending a number to the static response body, and running caddy reload --config /etc/caddy/Caddyfile:

{"level":"info","ts":1764181205.652986,"logger":"admin.api","msg":"received request","method":"POST","host":"localhost:2019","uri":"/load","remote_ip":"127.0.0.1","remote_port":"53638","headers":{"Accept-Encoding":["gzip"],"Content-Length":["1513"],"Content-Type":["application/json"],"Origin":["http://localhost:2019"],"User-Agent":["Go-http-client/1.1"]}}
{"level":"info","ts":1764181205.6536577,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
{"level":"warn","ts":1764181205.6540132,"logger":"http.handlers.cache","msg":"You're running Souin with the default storage that is not optimized and for development purpose. We recommend to use at least one of the storages from https://github.com/darkweak/storages"}
{"level":"info","ts":1764181205.654029,"logger":"http.handlers.cache","msg":"Set backend timeout to 10s"}
{"level":"info","ts":1764181205.6540427,"logger":"http.handlers.cache","msg":"Set cache timeout to 10ms"}
{"level":"info","ts":1764181205.6540506,"logger":"http.handlers.cache","msg":"Souin configuration is now loaded."}
{"level":"warn","ts":1764181205.6541312,"logger":"http","msg":"HTTP/2 skipped because it requires TLS","network":"tcp","addr":":4443"}
{"level":"warn","ts":1764181205.6541579,"logger":"http","msg":"HTTP/3 skipped because it requires TLS","network":"tcp","addr":":4443"}
{"level":"info","ts":1764181205.6541655,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
{"level":"info","ts":1764181205.6541889,"logger":"http","msg":"servers shutting down with eternal grace period"}
{"level":"info","ts":1764181205.6543622,"msg":"autosaved config (load with --resume flag)","file":"/root/.config/caddy/autosave.json"}
{"level":"info","ts":1764181205.6543758,"logger":"admin.api","msg":"load complete"}
{"level":"info","ts":1764181205.654874,"logger":"admin","msg":"stopped previous server","address":"localhost:2019"}

Note the You're running Souin with the default storage that is not optimized and for development purpose. We recommend to use at least one of the storages from https://github.com/darkweak/storages message.

Afterwards the cache is gone, note the uri-miss in the Cache-Status header:

$ curl -i localhost:4443/nuts-configuration
HTTP/1.1 200 OK
Cache-Control:
Cache-Status: Souin; fwd=uri-miss; stored; key=GET-http-localhost:4443-/nuts-configuration
Content-Length: 11
Content-Type: text/plain; charset=utf-8
Server: Caddy
Date: Wed, 26 Nov 2025 18:26:10 GMT
Hello nuts2

After a complete Caddy restart, the cache will be back!

This is my Caddyfile:

:4443
respond "Hello World!"
route /nuts-configuration {
    cache {
        ttl 1500s
        nuts {
            configuration {
                Dir /tmp/nuts-configuration
                EntryIdxMode 1
                RWMode 0
                SegmentSize 1024
                NodeNum 42
                SyncEnable true
                StartFileLoadingMode 1
            }
        }
    }
    respond "Hello nuts"
}
主要语言
Go
星标
396
派生
29
平均合并
32 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

caddyserver/cache-handler 的其他 Issue

查看 caddyserver/cache-handler 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。