Skip to content

Commit b0cc90a

Browse files
committed
gobuild: rename s3cache.Cache to gobuild.S3Cache
1 parent f149cc2 commit b0cc90a

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

cmd/go-cache-plugin/setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727
"github.com/creachadair/taskgroup"
2828
"github.com/creachadair/tlsutil"
2929
"github.com/goproxy/goproxy"
30+
"github.com/tailscale/go-cache-plugin/gobuild"
3031
"github.com/tailscale/go-cache-plugin/lib/s3util"
3132
"github.com/tailscale/go-cache-plugin/revproxy"
32-
"github.com/tailscale/go-cache-plugin/s3cache"
3333
"github.com/tailscale/go-cache-plugin/s3proxy"
3434
"tailscale.com/tsweb"
3535
)
@@ -62,7 +62,7 @@ func initCacheServer(env *command.Env) (*gocache.Server, *s3util.Client, error)
6262
Client: s3.NewFromConfig(cfg),
6363
Bucket: flags.S3Bucket,
6464
}
65-
cache := &s3cache.Cache{
65+
cache := &gobuild.S3Cache{
6666
Local: dir,
6767
S3Client: client,
6868
KeyPrefix: flags.KeyPrefix,

s3cache/s3cache.go renamed to gobuild/gobuild.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
// Package s3cache implements callbacks for a gocache.Server that store data
4+
// Package gobuild implements callbacks for a gocache.Server that store data
55
// into an S3 bucket through a local directory.
6-
package s3cache
6+
package gobuild
77

88
import (
99
"bytes"
@@ -26,7 +26,7 @@ import (
2626
"github.com/tailscale/go-cache-plugin/lib/s3util"
2727
)
2828

29-
// Cache implements callbacks for a gocache.Server using an S3 bucket for
29+
// S3Cache implements callbacks for a gocache.Server using an S3 bucket for
3030
// backing store with a local directory for staging.
3131
//
3232
// # Remote Cache Layout
@@ -49,7 +49,7 @@ import (
4949
//
5050
// where the object ID is hex encoded and the timestamp is Unix nanoseconds.
5151
// The object file contains just the binary data of the object.
52-
type Cache struct {
52+
type S3Cache struct {
5353
// Local is the local cache directory where actions and objects are staged.
5454
// It must be non-nil. A local stage is required because the Go toolchain
5555
// needs direct access to read the files reported by the cache.
@@ -88,14 +88,14 @@ type Cache struct {
8888
putS3Error expvar.Int // count of errors writing to S3
8989
}
9090

91-
func (s *Cache) init() {
91+
func (s *S3Cache) init() {
9292
s.initOnce.Do(func() {
9393
s.push, s.start = taskgroup.New(nil).Limit(s.uploadConcurrency())
9494
})
9595
}
9696

9797
// Get implements the corresponding callback of the cache protocol.
98-
func (s *Cache) Get(ctx context.Context, actionID string) (objectID, diskPath string, _ error) {
98+
func (s *S3Cache) Get(ctx context.Context, actionID string) (objectID, diskPath string, _ error) {
9999
s.init()
100100

101101
objID, diskPath, err := s.Local.Get(ctx, actionID)
@@ -142,7 +142,7 @@ func (s *Cache) Get(ctx context.Context, actionID string) (objectID, diskPath st
142142
}
143143

144144
// Put implements the corresponding callback of the cache protocol.
145-
func (s *Cache) Put(ctx context.Context, obj gocache.Object) (diskPath string, _ error) {
145+
func (s *S3Cache) Put(ctx context.Context, obj gocache.Object) (diskPath string, _ error) {
146146
s.init()
147147

148148
// Compute an etag so we can do a conditional put on the object data.
@@ -187,7 +187,7 @@ func (s *Cache) Put(ctx context.Context, obj gocache.Object) (diskPath string, _
187187
}
188188

189189
// Close implements the corresponding callback of the cache protocol.
190-
func (s *Cache) Close(ctx context.Context) error {
190+
func (s *S3Cache) Close(ctx context.Context) error {
191191
if s.push != nil {
192192
gocache.Logf(ctx, "waiting for uploads...")
193193
wstart := time.Now()
@@ -198,7 +198,7 @@ func (s *Cache) Close(ctx context.Context) error {
198198
}
199199

200200
// SetMetrics implements the corresponding server callback.
201-
func (s *Cache) SetMetrics(_ context.Context, m *expvar.Map) {
201+
func (s *S3Cache) SetMetrics(_ context.Context, m *expvar.Map) {
202202
m.Set("get_local_hit", &s.getLocalHit)
203203
m.Set("get_fault_hit", &s.getFaultHit)
204204
m.Set("get_fault_miss", &s.getFaultMiss)
@@ -212,7 +212,7 @@ func (s *Cache) SetMetrics(_ context.Context, m *expvar.Map) {
212212
// maybePutObject writes the specified object contents to S3 if there is not
213213
// already a matching key with the same etag. It returns the modified time of
214214
// the object file, whether or not it was sent to S3.
215-
func (s *Cache) maybePutObject(ctx context.Context, objectID, diskPath, etag string) (time.Time, error) {
215+
func (s *S3Cache) maybePutObject(ctx context.Context, objectID, diskPath, etag string) (time.Time, error) {
216216
f, err := os.Open(diskPath)
217217
if err != nil {
218218
gocache.Logf(ctx, "[s3] open local object %s: %v", objectID, err)
@@ -240,14 +240,14 @@ func (s *Cache) maybePutObject(ctx context.Context, objectID, diskPath, etag str
240240

241241
// makeKey assembles a complete key from the specified parts, including the key
242242
// prefix if one is defined.
243-
func (s *Cache) makeKey(parts ...string) string {
243+
func (s *S3Cache) makeKey(parts ...string) string {
244244
return path.Join(s.KeyPrefix, path.Join(parts...))
245245
}
246246

247-
func (s *Cache) actionKey(id string) string { return s.makeKey("action", id[:2], id) }
248-
func (s *Cache) objectKey(id string) string { return s.makeKey("object", id[:2], id) }
247+
func (s *S3Cache) actionKey(id string) string { return s.makeKey("action", id[:2], id) }
248+
func (s *S3Cache) objectKey(id string) string { return s.makeKey("object", id[:2], id) }
249249

250-
func (s *Cache) uploadConcurrency() int {
250+
func (s *S3Cache) uploadConcurrency() int {
251251
if s.UploadConcurrency <= 0 {
252252
return runtime.NumCPU()
253253
}

0 commit comments

Comments
 (0)