libyear/pkg/cache/cache.go
2021-05-09 17:25:23 -04:00

27 lines
592 B
Go

package cache
import "git.yetaga.in/alazyreader/libyear/pkg/libyear"
// Cache holds maps of strings to Info structs.
// It isn't concurrency-safe, but we don't care about that right now.
type Cache struct {
items map[string]libyear.Info
}
// Get retrives an Info struct from the cache, if it exists.
func (c *Cache) Get(k string) libyear.Info {
i, ok := c.items[k]
if ok {
return i
}
return libyear.Info{}
}
// Set adds an Info struct to the cache.
func (c *Cache) Set(k string, v libyear.Info) {
if c.items == nil {
c.items = make(map[string]libyear.Info)
}
c.items[k] = v
}