1package backend
 2
 3import lru "github.com/hashicorp/golang-lru/v2"
 4
 5// TODO: implement a caching interface.
 6type cache struct {
 7	b     *Backend
 8	repos *lru.Cache[string, *repo]
 9}
10
11func newCache(b *Backend, size int) *cache {
12	if size <= 0 {
13		size = 1
14	}
15	c := &cache{b: b}
16	cache, _ := lru.New[string, *repo](size)
17	c.repos = cache
18	return c
19}
20
21func (c *cache) Get(repo string) (*repo, bool) {
22	return c.repos.Get(repo)
23}
24
25func (c *cache) Set(repo string, r *repo) {
26	c.repos.Add(repo, r)
27}
28
29func (c *cache) Delete(repo string) {
30	c.repos.Remove(repo)
31}
32
33func (c *cache) Len() int {
34	return c.repos.Len()
35}