registry/storage/cache/memory: Use LRU cache to bound cache size

Instead of letting the cache grow without bound, use a LRU to impose a
size limit.

The limit is configurable through a new `blobdescriptorsize` config key.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
This commit is contained in:
Aaron Lehmann
2022-07-12 17:42:48 -07:00
parent 0122d7ddae
commit e36cb0a5d8
24 changed files with 1417 additions and 125 deletions

View File

@@ -13,6 +13,7 @@ import (
"os"
"regexp"
"runtime"
"strconv"
"strings"
"time"
@@ -272,6 +273,9 @@ func NewApp(ctx context.Context, config *configuration.Configuration) *App {
if app.redis == nil {
panic("redis configuration required to use for layerinfo cache")
}
if _, ok := cc["blobdescriptorsize"]; ok {
dcontext.GetLogger(app).Warnf("blobdescriptorsize parameter is not supported with redis cache")
}
cacheProvider := rediscache.NewRedisBlobDescriptorCacheProvider(app.redis)
localOptions := append(options, storage.BlobDescriptorCacheProvider(cacheProvider))
app.registry, err = storage.NewRegistry(app, app.driver, localOptions...)
@@ -280,7 +284,17 @@ func NewApp(ctx context.Context, config *configuration.Configuration) *App {
}
dcontext.GetLogger(app).Infof("using redis blob descriptor cache")
case "inmemory":
cacheProvider := memorycache.NewInMemoryBlobDescriptorCacheProvider()
blobDescriptorSize := memorycache.DefaultSize
configuredSize, ok := cc["blobdescriptorsize"]
if ok {
// Since Parameters is not strongly typed, render to a string and convert back
blobDescriptorSize, err = strconv.Atoi(fmt.Sprint(configuredSize))
if err != nil {
panic(fmt.Sprintf("invalid blobdescriptorsize value %s: %s", configuredSize, err))
}
}
cacheProvider := memorycache.NewInMemoryBlobDescriptorCacheProvider(blobDescriptorSize)
localOptions := append(options, storage.BlobDescriptorCacheProvider(cacheProvider))
app.registry, err = storage.NewRegistry(app, app.driver, localOptions...)
if err != nil {