cachevalue: simplify exported interface (#19137)

- Also add cache options type
This commit is contained in:
Aditya Manthramurthy
2024-02-28 09:09:09 -08:00
committed by GitHub
parent 2bdb9511bd
commit 62ce52c8fd
10 changed files with 98 additions and 103 deletions

View File

@@ -47,20 +47,15 @@ var bucketStorageCache = cachevalue.New[DataUsageInfo]()
// Init initialize bucket quota.
func (sys *BucketQuotaSys) Init(objAPI ObjectLayer) {
bucketStorageCache.Once.Do(func() {
// Set this to 10 secs since its enough, as scanner
// does not update the bucket usage values frequently.
bucketStorageCache.TTL = 10 * time.Second
// Rely on older value if usage loading fails from disk.
bucketStorageCache.ReturnLastGood = true
bucketStorageCache.NoWait = true
bucketStorageCache.Update = func() (DataUsageInfo, error) {
bucketStorageCache.InitOnce(10*time.Second,
cachevalue.Opts{ReturnLastGood: true, NoWait: true},
func() (DataUsageInfo, error) {
ctx, done := context.WithTimeout(context.Background(), 2*time.Second)
defer done()
return loadDataUsageFromBackend(ctx, objAPI)
}
})
},
)
}
// GetBucketUsageInfo return bucket usage info for a given bucket