lru_interface.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Package simplelru provides simple LRU implementation based on build-in container/list.
  2. package simplelru
  3. // LRUCache is the interface for simple LRU cache.
  4. type 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. // Returns key's value from the cache and
  9. // updates the "recently used"-ness of the key. #value, isFound
  10. Get(key interface{}) (value interface{}, ok bool)
  11. // Checks if a key exists in cache without updating the recent-ness.
  12. Contains(key interface{}) (ok bool)
  13. // Returns key's value without updating the "recently used"-ness of the key.
  14. Peek(key interface{}) (value interface{}, ok bool)
  15. // Removes a key from the cache.
  16. Remove(key interface{}) bool
  17. // Removes the oldest entry from cache.
  18. RemoveOldest() (interface{}, interface{}, bool)
  19. // Returns the oldest entry from the cache. #key, value, isFound
  20. GetOldest() (interface{}, interface{}, bool)
  21. // Returns a slice of the keys in the cache, from oldest to newest.
  22. Keys() []interface{}
  23. // Returns the number of items in the cache.
  24. Len() int
  25. // Clears all cache entries.
  26. Purge()
  27. // Resizes cache, returning number evicted
  28. Resize(int) int
  29. }