Skip to content

Commit

Permalink
Add allKeys getter
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixLisczyk authored and nicklockwood committed Jan 20, 2024
1 parent 6d2b524 commit 184afdd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Sources/LRUCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ public extension LRUCache {
values.isEmpty
}

/// Returns all keys in the cache from oldest to newest
var allKeys: [Key] {
lock.lock()
defer { lock.unlock() }
var keys = [Key]()
var next = head
while let container = next {
keys.append(container.key)
next = container.next
}
return keys
}

/// Returns all values in the cache from oldest to newest
var allValues: [Value] {
lock.lock()
Expand Down

0 comments on commit 184afdd

Please sign in to comment.