@@ -22,20 +22,20 @@ import (
22
22
// NewFromStore returns a file cache that will fetch files from the provided
23
23
// database.
24
24
func NewFromStore (store database.Store , registerer prometheus.Registerer , authz rbac.Authorizer ) * Cache {
25
- fetch := func (ctx context.Context , fileID uuid.UUID ) (cacheEntryValue , error ) {
25
+ fetch := func (ctx context.Context , fileID uuid.UUID ) (CacheEntryValue , error ) {
26
26
// Make sure the read does not fail due to authorization issues.
27
27
// Authz is checked on the Acquire call, so this is safe.
28
28
//nolint:gocritic
29
29
file , err := store .GetFileByID (dbauthz .AsFileReader (ctx ), fileID )
30
30
if err != nil {
31
- return cacheEntryValue {}, xerrors .Errorf ("failed to read file from database: %w" , err )
31
+ return CacheEntryValue {}, xerrors .Errorf ("failed to read file from database: %w" , err )
32
32
}
33
33
34
34
content := bytes .NewBuffer (file .Data )
35
- return cacheEntryValue {
36
- object : file .RBACObject (),
35
+ return CacheEntryValue {
36
+ Object : file .RBACObject (),
37
37
FS : archivefs .FromTarReader (content ),
38
- size : int64 (content .Len ()),
38
+ Size : int64 (content .Len ()),
39
39
}, nil
40
40
}
41
41
@@ -126,19 +126,19 @@ type cacheMetrics struct {
126
126
totalCacheSize prometheus.Counter
127
127
}
128
128
129
- type cacheEntryValue struct {
130
- object rbac.Object
129
+ type CacheEntryValue struct {
130
+ Object rbac.Object
131
131
fs.FS
132
- size int64
132
+ Size int64
133
133
}
134
134
135
135
type cacheEntry struct {
136
136
// refCount must only be accessed while the Cache lock is held.
137
137
refCount int
138
- value * lazy.ValueWithError [cacheEntryValue ]
138
+ value * lazy.ValueWithError [CacheEntryValue ]
139
139
}
140
140
141
- type fetcher func (context.Context , uuid.UUID ) (cacheEntryValue , error )
141
+ type fetcher func (context.Context , uuid.UUID ) (CacheEntryValue , error )
142
142
143
143
// Acquire will load the fs.FS for the given file. It guarantees that parallel
144
144
// calls for the same fileID will only result in one fetch, and that parallel
@@ -162,27 +162,27 @@ func (c *Cache) Acquire(ctx context.Context, fileID uuid.UUID) (fs.FS, error) {
162
162
return nil , dbauthz .ErrNoActor
163
163
}
164
164
// Always check the caller can actually read the file.
165
- if err := c .authz .Authorize (ctx , subject , policy .ActionRead , it .object ); err != nil {
165
+ if err := c .authz .Authorize (ctx , subject , policy .ActionRead , it .Object ); err != nil {
166
166
c .Release (fileID )
167
167
return nil , err
168
168
}
169
169
170
170
return it .FS , err
171
171
}
172
172
173
- func (c * Cache ) prepare (ctx context.Context , fileID uuid.UUID ) * lazy.ValueWithError [cacheEntryValue ] {
173
+ func (c * Cache ) prepare (ctx context.Context , fileID uuid.UUID ) * lazy.ValueWithError [CacheEntryValue ] {
174
174
c .lock .Lock ()
175
175
defer c .lock .Unlock ()
176
176
177
177
entry , ok := c .data [fileID ]
178
178
if ! ok {
179
- value := lazy .NewWithError (func () (cacheEntryValue , error ) {
179
+ value := lazy .NewWithError (func () (CacheEntryValue , error ) {
180
180
val , err := c .fetcher (ctx , fileID )
181
181
182
182
// Always add to the cache size the bytes of the file loaded.
183
183
if err == nil {
184
- c .currentCacheSize .Add (float64 (val .size ))
185
- c .totalCacheSize .Add (float64 (val .size ))
184
+ c .currentCacheSize .Add (float64 (val .Size ))
185
+ c .totalCacheSize .Add (float64 (val .Size ))
186
186
}
187
187
188
188
return val , err
@@ -227,7 +227,7 @@ func (c *Cache) Release(fileID uuid.UUID) {
227
227
228
228
ev , err := entry .value .Load ()
229
229
if err == nil {
230
- c .currentCacheSize .Add (- 1 * float64 (ev .size ))
230
+ c .currentCacheSize .Add (- 1 * float64 (ev .Size ))
231
231
}
232
232
233
233
delete (c .data , fileID )
0 commit comments