dongya2029 2018-08-29 17:06
浏览 39
已采纳

如何找到Go模块的源缓存?

I've upgraded a project to Go 1.11 and enabled module support for my project, but it seems that CircleCI is re-downloading the dependencies on every build. I know CircleCI allows caching between rebuilds, so I've looked at the documentation for Go modules, and while it mentions a cache, I can't seem to find where it actually exists.

Where is the source cache for Go modules?

  • 写回答

1条回答 默认 最新

  • dongpin2969 2018-08-29 17:11
    关注

    As of the final 1.11 release, the go module cache (used for storing downloaded modules and source code), is in the $GOPATH/pkg/mod location (see the docs here). For clarification, the go build cache (used for storing recent compilation results) is in a different location.

    This article, indicated that it's in the $GOPATH/src/mod, but in the timespan of the recent ~40 days, the golang team must have changed that target location. This message thread has some discussion on why the downloaded items ended up in $GOPATH/pkg.

    You can also use the go mod download -json command to see the downloaded modules/source metadata and their location on your local disk. Example output below:

    $ go mod download -json
    go: finding github.com/aws/aws-sdk-go v1.14.5
    go: finding github.com/aws/aws-lambda-go v1.2.0
    {
        "Path": "github.com/aws/aws-lambda-go",
        "Version": "v1.2.0",
        "Info": "/go/pkg/mod/cache/download/github.com/aws/aws-lambda-go/@v/v1.2.0.info",
        "GoMod": "/go/pkg/mod/cache/download/github.com/aws/aws-lambda-go/@v/v1.2.0.mod",
        "Zip": "/go/pkg/mod/cache/download/github.com/aws/aws-lambda-go/@v/v1.2.0.zip",
        "Dir": "/go/pkg/mod/github.com/aws/aws-lambda-go@v1.2.0",
        "Sum": "h1:2f0pbAKMNNhvOkjI9BCrwoeIiduSTlYpD0iKEN1neuQ=",
        "GoModSum": "h1:zUsUQhAUjYzR8AuduJPCfhBuKWUaDbQiPOG+ouzmE1A="
    }
    {
        "Path": "github.com/aws/aws-sdk-go",
        "Version": "v1.14.5",
        "Info": "/go/pkg/mod/cache/download/github.com/aws/aws-sdk-go/@v/v1.14.5.info",
        "GoMod": "/go/pkg/mod/cache/download/github.com/aws/aws-sdk-go/@v/v1.14.5.mod",
        "Zip": "/go/pkg/mod/cache/download/github.com/aws/aws-sdk-go/@v/v1.14.5.zip",
        "Dir": "/go/pkg/mod/github.com/aws/aws-sdk-go@v1.14.5",
        "Sum": "h1:+l1m6QH6LypE2kL0p/G0Oh7ceCv+IVQ1h5UEBt2xjjU=",
        "GoModSum": "h1:ZRmQr0FajVIyZ4ZzBYKG5P3ZqPz9IHG41ZoMu1ADI3k="
    }
    

    That output is from a build on CircleCI 2.0, using their official circleci/golang:1.11 image. This is a contrived example to show how you would include the restore_cache and save_cache steps for the new golang module cache location:

    steps:
        - checkout
        - restore_cache:
           keys:
             - gomod-cache-{{ checksum "go.sum" }}
        - run: go vet ./...
        - save_cache:
            key: gomod-cache-{{ checksum "go.sum" }}
            paths:
              - /go/pkg/mod
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口