@@ -17,7 +17,6 @@ import (
17
17
"sync"
18
18
"time"
19
19
20
- "github.com/aws/aws-sdk-go-v2/service/s3"
21
20
"github.com/creachadair/gocache"
22
21
"github.com/creachadair/gocache/cachedir"
23
22
"github.com/creachadair/taskgroup"
@@ -56,11 +55,7 @@ type Cache struct {
56
55
57
56
// S3Client is the S3 client used to read and write cache entries to the
58
57
// 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
64
59
65
60
// KeyPrefix, if non-empty, is prepended to each key stored into S3, with an
66
61
// intervening slash.
@@ -79,7 +74,6 @@ type Cache struct {
79
74
initOnce sync.Once
80
75
push * taskgroup.Group
81
76
start func (taskgroup.Task ) * taskgroup.Group
82
- client * s3util.Client
83
77
84
78
getLocalHit expvar.Int // count of Get hits in the local cache
85
79
getFaultHit expvar.Int // count of Get hits faulted in from S3
@@ -94,7 +88,6 @@ type Cache struct {
94
88
func (s * Cache ) init () {
95
89
s .initOnce .Do (func () {
96
90
s .push , s .start = taskgroup .New (nil ).Limit (s .uploadConcurrency ())
97
- s .client = & s3util.Client {Client : s .S3Client , Bucket : s .S3Bucket }
98
91
})
99
92
}
100
93
@@ -110,7 +103,7 @@ func (s *Cache) Get(ctx context.Context, actionID string) (objectID, diskPath st
110
103
111
104
// Reaching here, either we got a cache miss or an error reading from local.
112
105
// 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 ))
114
107
if err != nil {
115
108
if errors .Is (err , fs .ErrNotExist ) {
116
109
s .getFaultMiss .Add (1 )
@@ -125,7 +118,7 @@ func (s *Cache) Get(ctx context.Context, actionID string) (objectID, diskPath st
125
118
return "" , "" , err
126
119
}
127
120
128
- object , err := s .client .GetData (ctx , s .objectKey (objectID ))
121
+ object , err := s .S3Client .GetData (ctx , s .objectKey (objectID ))
129
122
if err != nil {
130
123
// At this point we know the action exists, so if we can't read the
131
124
// 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, _
178
171
}
179
172
180
173
// 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 ),
182
175
strings .NewReader (fmt .Sprintf ("%s %d" , obj .ObjectID , mtime .UnixNano ()))); err != nil {
183
176
gocache .Logf (ctx , "write action %s: %v" , obj .ActionID , err )
184
177
return err
@@ -228,7 +221,7 @@ func (s *Cache) maybePutObject(ctx context.Context, objectID, diskPath, etag str
228
221
return time.Time {}, err
229
222
}
230
223
231
- written , err := s .client .PutCond (ctx , s .objectKey (objectID ), etag , f )
224
+ written , err := s .S3Client .PutCond (ctx , s .objectKey (objectID ), etag , f )
232
225
if err != nil {
233
226
s .putS3Error .Add (1 )
234
227
gocache .Logf (ctx , "[s3] put object %s: %v" , objectID , err )
0 commit comments