1package cache
2
3import (
4 "math"
5
6 lru "github.com/hashicorp/golang-lru/v2"
7
8 "github.com/git-bug/git-bug/entity"
9)
10
11type lruIdCache struct {
12 *lru.Cache[entity.Id, *struct{}]
13}
14
15func newLRUIdCache() lruIdCache {
16 // we can ignore the error here as it would only fail if the size is negative.
17 cache, _ := lru.New[entity.Id, *struct{}](math.MaxInt32)
18 return lruIdCache{Cache: cache}
19}
20
21func (c *lruIdCache) Add(id entity.Id) bool {
22 return c.Cache.Add(id, nil)
23}
24func (c *lruIdCache) GetOldest() (entity.Id, bool) {
25 id, _, present := c.Cache.GetOldest()
26 return id, present
27}
28
29func (c *lruIdCache) GetOldestToNewest() (ids []entity.Id) {
30 return c.Keys()
31}