Skip to content

Commit 966d909

Browse files
committed
s3cache: use s3util.Client directly instead of internally
1 parent 4ca4640 commit 966d909

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

s3cache/s3cache.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"sync"
1818
"time"
1919

20-
"github.com/aws/aws-sdk-go-v2/service/s3"
2120
"github.com/creachadair/gocache"
2221
"github.com/creachadair/gocache/cachedir"
2322
"github.com/creachadair/taskgroup"
@@ -56,11 +55,7 @@ type Cache struct {
5655

5756
// S3Client is the S3 client used to read and write cache entries to the
5857
// backing store. It must be non-nil.
59-
S3Client *s3.Client
60-
61-
// S3Bucket is the name of the S3 bucket where cache entries are stored.
62-
// It must be non-empty.
63-
S3Bucket string
58+
S3Client *s3util.Client
6459

6560
// KeyPrefix, if non-empty, is prepended to each key stored into S3, with an
6661
// intervening slash.
@@ -79,7 +74,6 @@ type Cache struct {
7974
initOnce sync.Once
8075
push *taskgroup.Group
8176
start func(taskgroup.Task) *taskgroup.Group
82-
client *s3util.Client
8377

8478
getLocalHit expvar.Int // count of Get hits in the local cache
8579
getFaultHit expvar.Int // count of Get hits faulted in from S3
@@ -94,7 +88,6 @@ type Cache struct {
9488
func (s *Cache) init() {
9589
s.initOnce.Do(func() {
9690
s.push, s.start = taskgroup.New(nil).Limit(s.uploadConcurrency())
97-
s.client = &s3util.Client{Client: s.S3Client, Bucket: s.S3Bucket}
9891
})
9992
}
10093

@@ -110,7 +103,7 @@ func (s *Cache) Get(ctx context.Context, actionID string) (objectID, diskPath st
110103

111104
// Reaching here, either we got a cache miss or an error reading from local.
112105
// Try reading the action from S3.
113-
action, err := s.client.GetData(ctx, s.actionKey(actionID))
106+
action, err := s.S3Client.GetData(ctx, s.actionKey(actionID))
114107
if err != nil {
115108
if errors.Is(err, fs.ErrNotExist) {
116109
s.getFaultMiss.Add(1)
@@ -125,7 +118,7 @@ func (s *Cache) Get(ctx context.Context, actionID string) (objectID, diskPath st
125118
return "", "", err
126119
}
127120

128-
object, err := s.client.GetData(ctx, s.objectKey(objectID))
121+
object, err := s.S3Client.GetData(ctx, s.objectKey(objectID))
129122
if err != nil {
130123
// At this point we know the action exists, so if we can't read the
131124
// object report it as an error rather than a cache miss.
@@ -178,7 +171,7 @@ func (s *Cache) Put(ctx context.Context, obj gocache.Object) (diskPath string, _
178171
}
179172

180173
// Stage 2: Write the action record.
181-
if err := s.client.Put(ctx, s.actionKey(obj.ActionID),
174+
if err := s.S3Client.Put(ctx, s.actionKey(obj.ActionID),
182175
strings.NewReader(fmt.Sprintf("%s %d", obj.ObjectID, mtime.UnixNano()))); err != nil {
183176
gocache.Logf(ctx, "write action %s: %v", obj.ActionID, err)
184177
return err
@@ -228,7 +221,7 @@ func (s *Cache) maybePutObject(ctx context.Context, objectID, diskPath, etag str
228221
return time.Time{}, err
229222
}
230223

231-
written, err := s.client.PutCond(ctx, s.objectKey(objectID), etag, f)
224+
written, err := s.S3Client.PutCond(ctx, s.objectKey(objectID), etag, f)
232225
if err != nil {
233226
s.putS3Error.Add(1)
234227
gocache.Logf(ctx, "[s3] put object %s: %v", objectID, err)

0 commit comments

Comments
 (0)