diff --git a/pkg/remote/aws/repository/ec2_repository.go b/pkg/remote/aws/repository/ec2_repository.go index 19532ad7..311fd103 100644 --- a/pkg/remote/aws/repository/ec2_repository.go +++ b/pkg/remote/aws/repository/ec2_repository.go @@ -24,7 +24,7 @@ type EC2Client interface { type ec2Repository struct { client ec2iface.EC2API - cache *cache.Cache + cache cache.Cache } func NewEC2Repository(session *session.Session) *ec2Repository { diff --git a/pkg/remote/cache/cache.go b/pkg/remote/cache/cache.go index 5d7d47c7..b0acbe3b 100644 --- a/pkg/remote/cache/cache.go +++ b/pkg/remote/cache/cache.go @@ -1,20 +1,27 @@ package cache -import "sync" +import ( + "sync" +) -type Cache struct { +type Cache interface { + Set(string, interface{}) bool + Get(string) interface{} +} + +type Store struct { mu *sync.RWMutex store map[string]interface{} } -func New() *Cache { - return &Cache{ +func New() Cache { + return &Store{ mu: &sync.RWMutex{}, store: map[string]interface{}{}, } } -func (c *Cache) Set(key string, value interface{}) (overridden bool) { +func (c *Store) Set(key string, value interface{}) (overridden bool) { c.mu.Lock() defer c.mu.Unlock() if _, ok := c.store[key]; ok { @@ -24,7 +31,7 @@ func (c *Cache) Set(key string, value interface{}) (overridden bool) { return } -func (c *Cache) Get(key string) interface{} { +func (c *Store) Get(key string) interface{} { c.mu.RLock() defer c.mu.RUnlock() return c.store[key]