Skip to content

Commit

Permalink
refactor: watchable cache store struct simplified
Browse files Browse the repository at this point in the history
Signed-off-by: Guilherme Cassolato <[email protected]>
  • Loading branch information
guicassolato committed Aug 6, 2024
1 parent 1c41c97 commit 11a66f3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions controller/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,38 +98,38 @@ func (c *cacheStore) Replace(store Store) {
}

type watchableCacheStore struct {
store watchable.Map[schema.GroupKind, RuntimeObjects]
watchable.Map[schema.GroupKind, RuntimeObjects]
}

func (c *watchableCacheStore) List() Store {
return c.store.LoadAll()
return c.LoadAll()
}

func (c *watchableCacheStore) Add(obj RuntimeObject) {
gk := obj.GetObjectKind().GroupVersionKind().GroupKind()
increment := RuntimeObjects{
string(obj.GetUID()): obj,
}
value, loaded := c.store.LoadOrStore(gk, increment)
value, loaded := c.LoadOrStore(gk, increment)
if !loaded {
return
}
value[string(obj.GetUID())] = obj
c.store.Store(gk, value)
c.Store(gk, value)
}

func (c *watchableCacheStore) Delete(obj RuntimeObject) {
gk := obj.GetObjectKind().GroupVersionKind().GroupKind()
value, ok := c.store.Load(gk)
value, ok := c.Load(gk)
if !ok {
return
}
delete(value, string(obj.GetUID()))
c.store.Store(gk, value)
c.Store(gk, value)
}

func (c *watchableCacheStore) Replace(store Store) {
for gk, objs := range store {
c.store.Store(gk, objs)
c.Store(gk, objs)
}
}

0 comments on commit 11a66f3

Please sign in to comment.