diff options
| author | jannfis <jann@mistrust.net> | 2020-08-27 20:53:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-27 20:53:33 +0200 |
| commit | 32ecfbba4725aa79e245082225e80f236fce5dc6 (patch) | |
| tree | aa2fa6bf7798188b94f4e28234e8386802b9f0f2 /pkg/cache | |
| parent | fac74674c7dd12c96f8444c14af273d4006789a5 (diff) | |
feat: Warm-up image cache on startup (#77)
* enhancement: Warm up cache before starting update cycle
* fix typos
* More typos
Diffstat (limited to 'pkg/cache')
| -rw-r--r-- | pkg/cache/cache.go | 8 | ||||
| -rw-r--r-- | pkg/cache/memcache.go | 25 |
2 files changed, 28 insertions, 5 deletions
diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index f207cb3..f3f3577 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -9,4 +9,12 @@ type ImageTagCache interface { GetTag(imageName string, imageTag string) (*tag.ImageTag, error) SetTag(imageName string, imgTag *tag.ImageTag) ClearCache() + NumEntries() int +} + +// KnownImage represents a known image and the applications using it, without +// any version/tag information. +type KnownImage struct { + ImageName string + Applications []string } diff --git a/pkg/cache/memcache.go b/pkg/cache/memcache.go index 63f47fd..bfc33f2 100644 --- a/pkg/cache/memcache.go +++ b/pkg/cache/memcache.go @@ -30,13 +30,15 @@ func (mc *MemCache) HasTag(imageName string, tagName string) bool { } } +// SetTag sets a tag entry into the cache func (mc *MemCache) SetTag(imageName string, imgTag *tag.ImageTag) { - mc.cache.Set(cacheKey(imageName, imgTag.TagName), *imgTag, -1) + mc.cache.Set(tagCacheKey(imageName, imgTag.TagName), *imgTag, -1) } +// GetTag gets a tag entry from the cache func (mc *MemCache) GetTag(imageName string, tagName string) (*tag.ImageTag, error) { var imgTag tag.ImageTag - e, ok := mc.cache.Get(cacheKey(imageName, tagName)) + e, ok := mc.cache.Get(tagCacheKey(imageName, tagName)) if !ok { return nil, nil } @@ -47,13 +49,26 @@ func (mc *MemCache) GetTag(imageName string, tagName string) (*tag.ImageTag, err return &imgTag, nil } -// Clears the cache +func (mc *MemCache) SetImage(imageName, application string) { + mc.cache.Set(imageCacheKey(imageName), application, -1) +} + +// ClearCache clears the cache func (mc *MemCache) ClearCache() { for k := range mc.cache.Items() { mc.cache.Delete(k) } } -func cacheKey(imageName, imageTag string) string { - return fmt.Sprintf("%s:%s", imageName, imageTag) +// NumEntries returns the number of entries in the cache +func (mc *MemCache) NumEntries() int { + return mc.cache.ItemCount() +} + +func tagCacheKey(imageName, imageTag string) string { + return fmt.Sprintf("tags:%s:%s", imageName, imageTag) +} + +func imageCacheKey(imageName string) string { + return fmt.Sprintf("image:%s", imageName) } |
