diff options
| author | Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com> | 2024-12-19 19:51:50 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-19 09:21:50 -0500 |
| commit | 736f12f55a73d17dbedc040b4f559a2cd33bbff4 (patch) | |
| tree | d7e31aba857641a20da7bffa5d9c29e3c5c230e4 /pkg/cache/memcache.go | |
| parent | 03203db49b047f03a8e99b26ef8554942c2513d6 (diff) | |
Update references of cache, env, health to use modules from registry-scanner (#972)
Signed-off-by: Ishita Sequeira <ishiseq29@gmail.com>
Diffstat (limited to 'pkg/cache/memcache.go')
| -rw-r--r-- | pkg/cache/memcache.go | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/pkg/cache/memcache.go b/pkg/cache/memcache.go deleted file mode 100644 index 03b4080..0000000 --- a/pkg/cache/memcache.go +++ /dev/null @@ -1,74 +0,0 @@ -package cache - -import ( - "fmt" - - "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/tag" - - memcache "github.com/patrickmn/go-cache" -) - -type MemCache struct { - cache *memcache.Cache -} - -// NewMemCache returns a new instance of MemCache -func NewMemCache() ImageTagCache { - mc := MemCache{} - c := memcache.New(0, 0) - mc.cache = c - return &mc -} - -// HasTag returns true if cache has entry for given tag, false if not -func (mc *MemCache) HasTag(imageName string, tagName string) bool { - tag, err := mc.GetTag(imageName, tagName) - if err != nil || tag == nil { - return false - } else { - return true - } -} - -// SetTag sets a tag entry into the cache -func (mc *MemCache) SetTag(imageName string, imgTag *tag.ImageTag) { - 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(tagCacheKey(imageName, tagName)) - if !ok { - return nil, nil - } - imgTag, ok = e.(tag.ImageTag) - if !ok { - return nil, fmt.Errorf("") - } - return &imgTag, nil -} - -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) - } -} - -// 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) -} |
