Browse code

bump hashicorp/golang-lru v0.5.3

full diff: https://github.com/hashicorp/golang-lru/compare/v0.5.1...v0.5.3

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/09/06 09:16:02
Showing 4 changed files
... ...
@@ -138,7 +138,7 @@ golang.org/x/crypto                                 88737f569e3a9c7ab309cdc09a07
138 138
 golang.org/x/time                                   fbb02b2291d28baffd63558aa44b4b56f178d650
139 139
 github.com/hashicorp/go-memdb                       cb9a474f84cc5e41b273b20c6927680b2a8776ad
140 140
 github.com/hashicorp/go-immutable-radix             826af9ccf0feeee615d546d69b11f8e98da8c8f1 git://github.com/tonistiigi/go-immutable-radix.git
141
-github.com/hashicorp/golang-lru                     7087cb70de9f7a8bc0a10c375cb0d2280a8edf9c # v0.5.1
141
+github.com/hashicorp/golang-lru                     7f827b33c0f158ec5dfbba01bb0b14a4541fd81d # v0.5.3
142 142
 github.com/coreos/pkg                               3ac0863d7acf3bc44daf49afef8919af12f704ef # v3
143 143
 code.cloudfoundry.org/clock                         02e53af36e6c978af692887ed449b74026d76fec
144 144
 
... ...
@@ -1 +1,3 @@
1 1
 module github.com/hashicorp/golang-lru
2
+
3
+go 1.12
... ...
@@ -73,6 +73,9 @@ func (c *LRU) Add(key, value interface{}) (evicted bool) {
73 73
 func (c *LRU) Get(key interface{}) (value interface{}, ok bool) {
74 74
 	if ent, ok := c.items[key]; ok {
75 75
 		c.evictList.MoveToFront(ent)
76
+		if ent.Value.(*entry) == nil {
77
+			return nil, false
78
+		}
76 79
 		return ent.Value.(*entry).value, true
77 80
 	}
78 81
 	return
... ...
@@ -142,6 +145,19 @@ func (c *LRU) Len() int {
142 142
 	return c.evictList.Len()
143 143
 }
144 144
 
145
+// Resize changes the cache size.
146
+func (c *LRU) Resize(size int) (evicted int) {
147
+	diff := c.Len() - size
148
+	if diff < 0 {
149
+		diff = 0
150
+	}
151
+	for i := 0; i < diff; i++ {
152
+		c.removeOldest()
153
+	}
154
+	c.size = size
155
+	return diff
156
+}
157
+
145 158
 // removeOldest removes the oldest item from the cache.
146 159
 func (c *LRU) removeOldest() {
147 160
 	ent := c.evictList.Back()
... ...
@@ -10,7 +10,7 @@ type LRUCache interface {
10 10
 	// updates the "recently used"-ness of the key. #value, isFound
11 11
 	Get(key interface{}) (value interface{}, ok bool)
12 12
 
13
-	// Check if a key exsists in cache without updating the recent-ness.
13
+	// Checks if a key exists in cache without updating the recent-ness.
14 14
 	Contains(key interface{}) (ok bool)
15 15
 
16 16
 	// Returns key's value without updating the "recently used"-ness of the key.
... ...
@@ -31,6 +31,9 @@ type LRUCache interface {
31 31
 	// Returns the number of items in the cache.
32 32
 	Len() int
33 33
 
34
-	// Clear all cache entries
34
+	// Clears all cache entries.
35 35
 	Purge()
36
+
37
+  // Resizes cache, returning number evicted
38
+  Resize(int) int
36 39
 }