在 Debian 系统下,“Golang 缓存清理”通常分几种场景,下面按常见情况给你说明。
Go 会缓存下载的模块(在 GOPATH/pkg/mod 和 GOCACHE 中)。
go env GOMODCACHE
go env GOCACHE
go clean -modcache
会删除
$GOPATH/pkg/mod下的所有模块缓存
go clean -cache
go clean -modcache -cache -testcache
go clean -testcache
强制下次
go test重新运行
go clean -i -r
或针对某个项目:
go clean
如果是公司内网 GOPROXY(如 Athens、Nexus):
如果是容器构建缓存:
docker system prune -a
或仅清理 Go 层缓存(在 Dockerfile 中):
RUN go clean -modcache
du -sh $(go env GOMODCACHE)
du -sh $(go env GOCACHE)
go clean -modcache -cache -testcache
如果你说的“缓存”是指 HTTP 缓存、Redis、文件缓存 或 某个具体 Go 程序,可以告诉我具体场景,我可以给更精准的方案。