diff options
author | Michael Muré <batolettre@gmail.com> | 2023-08-11 15:12:28 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2023-08-11 15:13:15 +0200 |
commit | f5e094f2c431f5a03d899b0866692e3534c72066 (patch) | |
tree | 4cd065e8f908869bf25835f7c522f4133f607f41 /cache/lru_id_cache.go | |
parent | e723f773f39de0ce152ec31227de3ec898846e2f (diff) | |
download | git-bug-f5e094f2c431f5a03d899b0866692e3534c72066.tar.gz |
update to golang-lru v2
Diffstat (limited to 'cache/lru_id_cache.go')
-rw-r--r-- | cache/lru_id_cache.go | 43 |
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() } |