Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame] | 1 | package simplelru |
| 2 | |
| 3 | |
| 4 | // LRUCache is the interface for simple LRU cache. |
| 5 | type LRUCache interface { |
| 6 | // Adds a value to the cache, returns true if an eviction occurred and |
| 7 | // updates the "recently used"-ness of the key. |
| 8 | Add(key, value interface{}) bool |
| 9 | |
| 10 | // Returns key's value from the cache and |
| 11 | // updates the "recently used"-ness of the key. #value, isFound |
| 12 | Get(key interface{}) (value interface{}, ok bool) |
| 13 | |
| 14 | // Check if a key exsists in cache without updating the recent-ness. |
| 15 | Contains(key interface{}) (ok bool) |
| 16 | |
| 17 | // Returns key's value without updating the "recently used"-ness of the key. |
| 18 | Peek(key interface{}) (value interface{}, ok bool) |
| 19 | |
| 20 | // Removes a key from the cache. |
| 21 | Remove(key interface{}) bool |
| 22 | |
| 23 | // Removes the oldest entry from cache. |
| 24 | RemoveOldest() (interface{}, interface{}, bool) |
| 25 | |
| 26 | // Returns the oldest entry from the cache. #key, value, isFound |
| 27 | GetOldest() (interface{}, interface{}, bool) |
| 28 | |
| 29 | // Returns a slice of the keys in the cache, from oldest to newest. |
| 30 | Keys() []interface{} |
| 31 | |
| 32 | // Returns the number of items in the cache. |
| 33 | Len() int |
| 34 | |
| 35 | // Clear all cache entries |
| 36 | Purge() |
| 37 | } |