lru.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package lru
  2. // LRU is the interface for simple LRU cache.
  3. type LRU interface {
  4. // Add Adds a value to the cache, returns true if an eviction occurred and
  5. // updates the "recently used"-ness of the key.
  6. Add(key, value any) bool
  7. // Get Returns key's value from the cache and
  8. // updates the "recently used"-ness of the key. #value, isFound
  9. Get(key any) (value any, ok bool)
  10. // Contains Checks if a key exists in cache without updating the recent-ness.
  11. Contains(key any) (ok bool)
  12. // Peek Returns key's value without updating the "recently used"-ness of the key.
  13. Peek(key any) (value any, ok bool)
  14. // Remove Removes a key from the cache.
  15. Remove(key any) bool
  16. // RemoveOldest Removes the oldest entry from cache.
  17. RemoveOldest() (any, any, bool)
  18. // GetOldest Returns the oldest entry from the cache. #key, value, isFound
  19. GetOldest() (any, any, bool)
  20. // Keys Returns a slice of the keys in the cache, from oldest to newest.
  21. Keys() []any
  22. // Values Returns a slice of the values in the cache, from oldest to newest.
  23. Values() []any
  24. // Len Returns the number of items in the cache.
  25. Len() int
  26. // Purge Clears all cache entries.
  27. Purge()
  28. // Resize Resizes cache, returning number evicted
  29. Resize(int) int
  30. }