aboutsummaryrefslogtreecommitdiffstats
path: root/cache/lru_id_cache.go
diff options
context:
space:
mode:
Diffstat (limited to 'cache/lru_id_cache.go')
-rw-r--r--cache/lru_id_cache.go43
1 files changed, 9 insertions, 34 deletions
diff --git a/cache/lru_id_cache.go b/cache/lru_id_cache.go
index 0e5e31a7..b76f5312 100644
--- a/cache/lru_id_cache.go
+++ b/cache/lru_id_cache.go
@@ -3,54 +3,29 @@ package cache
import (
"math"
- lru "github.com/hashicorp/golang-lru"
+ lru "github.com/hashicorp/golang-lru/v2"
"github.com/MichaelMure/git-bug/entity"
)
type lruIdCache struct {
- lru *lru.Cache
+ *lru.Cache[entity.Id, *struct{}]
}
-func newLRUIdCache() *lruIdCache {
+func newLRUIdCache() lruIdCache {
// we can ignore the error here as it would only fail if the size is negative.
- cache, _ := lru.New(math.MaxInt32)
-
- return &lruIdCache{
- cache,
- }
+ cache, _ := lru.New[entity.Id, *struct{}](math.MaxInt32)
+ return lruIdCache{Cache: cache}
}
func (c *lruIdCache) Add(id entity.Id) bool {
- return c.lru.Add(id, nil)
-}
-
-func (c *lruIdCache) Contains(id entity.Id) bool {
- return c.lru.Contains(id)
-}
-
-func (c *lruIdCache) Get(id entity.Id) bool {
- _, present := c.lru.Get(id)
- return present
+ return c.Cache.Add(id, nil)
}
-
func (c *lruIdCache) GetOldest() (entity.Id, bool) {
- id, _, present := c.lru.GetOldest()
- return id.(entity.Id), present
+ id, _, present := c.Cache.GetOldest()
+ return id, present
}
func (c *lruIdCache) GetOldestToNewest() (ids []entity.Id) {
- interfaceKeys := c.lru.Keys()
- for _, id := range interfaceKeys {
- ids = append(ids, id.(entity.Id))
- }
- return
-}
-
-func (c *lruIdCache) Len() int {
- return c.lru.Len()
-}
-
-func (c *lruIdCache) Remove(id entity.Id) bool {
- return c.lru.Remove(id)
+ return c.Keys()
}