- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我始终使用-i标志进行构建以安装软件包,并且.a文件安装在GOPATH/pkg目录中。go env GOCACHE
显示的GOCACHE目录似乎也存储高速缓存文件。
它们之间有什么区别?
我想知道,如果我想缩短构建时间,应该同时保存这两个文件吗?
最佳答案
TLDR; 缓存文件夹在go
工具内部,其工作对用户来说应该是不透明的,其目的是加快构建和测试的速度。例如,如果您使用版本控制系统(例如git
),在分支或版本之间切换,则GOPATH/pkg
可能仅包含一个版本的软件包文件。 go缓存文件夹可能包含(部分)多个分支和版本的已编译软件包,当您在分支和版本之间切换时,可以加快将来的构建速度。
缓存文件夹是在Go 1.10中引入的:
The
go build
command now maintains a cache of recently built packages, separate from the installed packages in$GOROOT/pkg
or$GOPATH/pkg
. The effect of the cache should be to speed builds that do not explicitly install packages or when switching between different copies of source code (for example, when changing back and forth between different branches in a version control system). The old advice to add the-i
flag for speed, as ingo build -i
orgo test -i
, is no longer necessary: builds run just as fast without-i
. For more details, seego help cache
.
-i
进行快速构建。
go help cache
输出的一些引号:
The go command caches build outputs for reuse in future builds. The default location for cache data is a subdirectory named go-build in the standard user cache directory for the current operating system. Setting the GOCACHE environment variable overrides this default, and running 'go env GOCACHE' prints the current cache directory.
The go command periodically deletes cached data that has not been used recently. Running 'go clean -cache' deletes all cached data.
The build cache correctly accounts for changes to Go source files, compilers, compiler options, and so on: cleaning the cache explicitly should not be necessary in typical use. However, the build cache does not detect changes to C libraries imported with cgo. If you have made changes to the C libraries on your system, you will need to clean the cache explicitly or else use the -a build flag (see 'go help build') to force rebuilding of packages that depend on the updated C libraries.
The go command also caches successful package test results. See 'go help test' for details. Running 'go clean -testcache' removes all cached test results (but not cached build results).
关于go - 已安装的软件包和GOCACHE有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57863793/
我必须把GO创建的所有文件都放在GO的结构里面,不能散乱。在更改 GOPATH 和 GOROOT 时,我注意到 ~/.cache/go-build 上的构建文件夹。 这SO thread根本没有帮助,
我是一名优秀的程序员,十分优秀!