@@ -21,6 +21,70 @@ go test ./...
2121Using the plugin requires a Go toolchain built with ` GOEXPERIMENT=cacheprog ` enabled.
2222However, you do not need the experiment enabled to build the plugin itself.
2323
24+ ## Discussion
25+
26+ The ` go-cache-plugin ` program supports two modes of operation:
27+
28+ 1 . ** Direct mode** : The program is invoked directly by the Go toolchain as a
29+ subprocess, and exits when the toolchain execution ends.
30+
31+ This is the default mode of operation, and requires no additional setup.
32+
33+ 2 . ** Server mode** : The program runs as a separate process and the Go toolchain
34+ communicates with it over a Unix-domain socket.
35+
36+ This mode requires the server to be started up ahead of time, but makes the
37+ configuration for the toolchain simpler. This mode also permits running an
38+ in-process module and sum database proxy.
39+
40+ ### Server Mode
41+
42+ To run in server mode, use the ` serve ` subcommand:
43+
44+ ``` sh
45+ # N.B.: The --socket flag is required.
46+ go-cache-plugin serve \
47+ --socket=/tmp/gocache.sock \
48+ --cache-dir=/tmp/gocache \
49+ --bucket=some-s3-bucket
50+ ```
51+
52+ To connect to a server running in this mode, use the ` connect ` subcommand:
53+
54+ ``` sh
55+ # Use the same socket path given to the server's --socket flag.
56+ export GOCACHEPROG=" go-cache-plugin connect /tmp/gocache.sock"
57+ go build ./...
58+ ```
59+
60+ The ` connect ` command just bridges the socket to stdin/stdout, which is how the
61+ Go toolchain expects to talk to the plugin.
62+
63+ ### Running a Module Proxy
64+
65+ To enable a caching module proxy, use the ` --modproxy ` flag to ` serve ` . The
66+ module proxy uses HTTP, not the plugin interface:
67+
68+ ``` sh
69+ go-cache-plugin serve \
70+ --socket=/tmp/gocache.sock \
71+ --modproxy=localhost:5970 \
72+ --cache-dir=/tmp/gocache \
73+ # ... other flags
74+ ```
75+
76+ To tell the Go toolchain about the proxy, set:
77+
78+ ``` sh
79+ export GOPROXY=http://localhost:5970 # use the --modcache address
80+ ```
81+
82+ If you want to also proxy queries to ` sum.golang.org ` , also add:
83+
84+ ``` sh
85+ export GOSUMDB=' sum.golang.org http://locahost:5970'
86+ ```
87+
2488## References
2589
2690- [ Cache plugin proposal] ( https://github.com/golang/go/issues/59719 )
0 commit comments