Resize changes the cache size. Size of 0 means unlimited.
(size int)
| 273 | |
| 274 | // Resize changes the cache size. Size of 0 means unlimited. |
| 275 | func (c *LRU[K, V]) Resize(size int) (evicted int) { |
| 276 | c.mu.Lock() |
| 277 | defer c.mu.Unlock() |
| 278 | if size <= 0 { |
| 279 | c.size = 0 |
| 280 | return 0 |
| 281 | } |
| 282 | diff := c.evictList.Length() - size |
| 283 | if diff < 0 { |
| 284 | diff = 0 |
| 285 | } |
| 286 | for i := 0; i < diff; i++ { |
| 287 | c.removeOldest() |
| 288 | } |
| 289 | c.size = size |
| 290 | return diff |
| 291 | } |
| 292 | |
| 293 | // Close destroys cleanup goroutine. To clean up the cache, run Purge() before Close(). |
| 294 | // func (c *LRU[K, V]) Close() { |