libyear/pkg/cache/cache.go

27 lines
592 B
Go
Raw Normal View History

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