mirror of
https://github.com/distribution/distribution.git
synced 2025-09-19 18:02:52 +00:00
Merge pull request #3993 from DavidSpek/update-golang-lru
Update github.com/hashicorp/golang-lru to v2
This commit is contained in:
18
registry/storage/cache/memory/memory.go
vendored
18
registry/storage/cache/memory/memory.go
vendored
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/distribution/distribution/v3"
|
||||
"github.com/distribution/distribution/v3/reference"
|
||||
"github.com/distribution/distribution/v3/registry/storage/cache"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/hashicorp/golang-lru/arc/v2"
|
||||
"github.com/opencontainers/go-digest"
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ type descriptorCacheKey struct {
|
||||
}
|
||||
|
||||
type inMemoryBlobDescriptorCacheProvider struct {
|
||||
lru *lru.ARCCache
|
||||
lru *arc.ARCCache[descriptorCacheKey, distribution.Descriptor]
|
||||
}
|
||||
|
||||
// NewInMemoryBlobDescriptorCacheProvider returns a new mapped-based cache for
|
||||
@@ -35,7 +35,7 @@ func NewInMemoryBlobDescriptorCacheProvider(size int) cache.BlobDescriptorCacheP
|
||||
if size <= 0 {
|
||||
size = math.MaxInt
|
||||
}
|
||||
lruCache, err := lru.NewARC(size)
|
||||
lruCache, err := arc.NewARC[descriptorCacheKey, distribution.Descriptor](size)
|
||||
if err != nil {
|
||||
// NewARC can only fail if size is <= 0, so this unreachable
|
||||
panic(err)
|
||||
@@ -66,11 +66,7 @@ func (imbdcp *inMemoryBlobDescriptorCacheProvider) Stat(ctx context.Context, dgs
|
||||
}
|
||||
descriptor, ok := imbdcp.lru.Get(key)
|
||||
if ok {
|
||||
// Type assertion not really necessary, but included in case
|
||||
// it's necessary for the fuzzer
|
||||
if desc, ok := descriptor.(distribution.Descriptor); ok {
|
||||
return desc, nil
|
||||
}
|
||||
return descriptor, nil
|
||||
}
|
||||
return distribution.Descriptor{}, distribution.ErrBlobUnknown
|
||||
}
|
||||
@@ -130,11 +126,7 @@ func (rsimbdcp *repositoryScopedInMemoryBlobDescriptorCache) Stat(ctx context.Co
|
||||
}
|
||||
descriptor, ok := rsimbdcp.parent.lru.Get(key)
|
||||
if ok {
|
||||
// Type assertion not really necessary, but included in case
|
||||
// it's necessary for the fuzzer
|
||||
if desc, ok := descriptor.(distribution.Descriptor); ok {
|
||||
return desc, nil
|
||||
}
|
||||
return descriptor, nil
|
||||
}
|
||||
return distribution.Descriptor{}, distribution.ErrBlobUnknown
|
||||
}
|
||||
|
Reference in New Issue
Block a user