summaryrefslogtreecommitdiffhomepage
path: root/util/lru/lru.go
diff options
context:
space:
mode:
Diffstat (limited to 'util/lru/lru.go')
-rw-r--r--util/lru/lru.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/util/lru/lru.go b/util/lru/lru.go
index 8e4dd417b..d4e836cf1 100644
--- a/util/lru/lru.go
+++ b/util/lru/lru.go
@@ -133,6 +133,15 @@ func (c *Cache[K, V]) DeleteOldest() {
}
}
+// OldestKey returns the oldest key, without bumping it to the head.
+// If the cache is empty, it returns ok false.
+func (c *Cache[K, V]) OldestKey() (key K, ok bool) {
+ if c.head == nil {
+ return key, false
+ }
+ return c.head.prev.key, true
+}
+
// Len returns the number of items in the cache.
func (c *Cache[K, V]) Len() int { return len(c.lookup) }