aboutsummaryrefslogtreecommitdiffstats
path: root/cache/lru_id_cache.go
diff options
context:
space:
mode:
authorvince <vincetiu8@gmail.com>2020-08-25 10:43:42 +0800
committervince <vincetiu8@gmail.com>2020-08-25 11:08:53 +0800
commit4b065029af63c16ffd754ac28190ba4b3125c494 (patch)
tree23a38eab9850b5408d65f33063b1643b4eca5b36 /cache/lru_id_cache.go
parent6efada43e73c40e0c76c441f84cf02cc00d3eb1b (diff)
downloadgit-bug-4b065029af63c16ffd754ac28190ba4b3125c494.tar.gz
Implement cache eviction and testing
Diffstat (limited to 'cache/lru_id_cache.go')
-rw-r--r--cache/lru_id_cache.go13
1 files changed, 5 insertions, 8 deletions
diff --git a/cache/lru_id_cache.go b/cache/lru_id_cache.go
index e31f2843..a387cb75 100644
--- a/cache/lru_id_cache.go
+++ b/cache/lru_id_cache.go
@@ -9,20 +9,16 @@ import (
type LRUIdCache struct {
parentCache *lru.Cache
maxSize int
- onEvict func(id entity.Id)
}
-func NewLRUIdCache(size int, onEvicted func(id entity.Id)) (*LRUIdCache, error) {
- cache, err := lru.New(size)
- if err != nil {
- return nil, err
- }
+func NewLRUIdCache(size int) *LRUIdCache {
+ // Ignore error here
+ cache, _ := lru.New(size)
return &LRUIdCache{
cache,
size,
- onEvicted,
- }, nil
+ }
}
func (c *LRUIdCache) Add(id entity.Id) bool {
@@ -60,5 +56,6 @@ func (c *LRUIdCache) Remove(id entity.Id) bool {
}
func (c *LRUIdCache) Resize(size int) int {
+ c.maxSize = size
return c.parentCache.Resize(size)
}