posh/pkg/cache/memorycache.go
Kevin Franklin Kim e2ad376b6c initial commit
2023-01-03 15:37:15 +01:00

29 lines
543 B
Go

package cache
type MemoryCache map[string]MemoryNamespace
func (c MemoryCache) Clear(namespace string) {
if namespace == "" {
for key := range c {
delete(c, key)
}
} else if _, ok := c[namespace]; ok {
delete(c, namespace)
}
}
func (c MemoryCache) Get(namespace string) Namespace {
if _, ok := c[namespace]; !ok {
c[namespace] = MemoryNamespace{}
}
return c[namespace]
}
func (c MemoryCache) List() map[string]Namespace {
ret := map[string]Namespace{}
for s, namespace := range c {
ret[s] = namespace
}
return ret
}