mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-12 15:16:29 +03:00
2004fa79e6
The repository was recently moved to the git-bug organization on github. This change refactors references to the repository to ensure that they use the updated owner URI. Closes: #1243 Change-Id: I799712354c6ba25cdd8b06286275850c52efe6ff
32 lines
658 B
Go
32 lines
658 B
Go
package cache
|
|
|
|
import (
|
|
"math"
|
|
|
|
lru "github.com/hashicorp/golang-lru/v2"
|
|
|
|
"github.com/git-bug/git-bug/entity"
|
|
)
|
|
|
|
type lruIdCache struct {
|
|
*lru.Cache[entity.Id, *struct{}]
|
|
}
|
|
|
|
func newLRUIdCache() lruIdCache {
|
|
// we can ignore the error here as it would only fail if the size is negative.
|
|
cache, _ := lru.New[entity.Id, *struct{}](math.MaxInt32)
|
|
return lruIdCache{Cache: cache}
|
|
}
|
|
|
|
func (c *lruIdCache) Add(id entity.Id) bool {
|
|
return c.Cache.Add(id, nil)
|
|
}
|
|
func (c *lruIdCache) GetOldest() (entity.Id, bool) {
|
|
id, _, present := c.Cache.GetOldest()
|
|
return id, present
|
|
}
|
|
|
|
func (c *lruIdCache) GetOldestToNewest() (ids []entity.Id) {
|
|
return c.Keys()
|
|
}
|