blob: 92d70934d632fc039f2f4b5365097f41f117a583 [file] [log] [blame]
William Kurkianea869482019-04-09 15:16:11 -04001package simplelru
2
3// LRUCache is the interface for simple LRU cache.
4type LRUCache interface {
5 // Adds a value to the cache, returns true if an eviction occurred and
6 // updates the "recently used"-ness of the key.
7 Add(key, value interface{}) bool
8
9 // Returns key's value from the cache and
10 // updates the "recently used"-ness of the key. #value, isFound
11 Get(key interface{}) (value interface{}, ok bool)
12
David Bainbridge788e5202019-10-21 18:49:40 +000013 // Checks if a key exists in cache without updating the recent-ness.
William Kurkianea869482019-04-09 15:16:11 -040014 Contains(key interface{}) (ok bool)
15
16 // Returns key's value without updating the "recently used"-ness of the key.
17 Peek(key interface{}) (value interface{}, ok bool)
18
19 // Removes a key from the cache.
20 Remove(key interface{}) bool
21
22 // Removes the oldest entry from cache.
23 RemoveOldest() (interface{}, interface{}, bool)
24
25 // Returns the oldest entry from the cache. #key, value, isFound
26 GetOldest() (interface{}, interface{}, bool)
27
28 // Returns a slice of the keys in the cache, from oldest to newest.
29 Keys() []interface{}
30
31 // Returns the number of items in the cache.
32 Len() int
33
David Bainbridge788e5202019-10-21 18:49:40 +000034 // Clears all cache entries.
William Kurkianea869482019-04-09 15:16:11 -040035 Purge()
David Bainbridge788e5202019-10-21 18:49:40 +000036
37 // Resizes cache, returning number evicted
38 Resize(int) int
William Kurkianea869482019-04-09 15:16:11 -040039}