From 7eac4668383a9b6f3301447702254d2a036157c5 Mon Sep 17 00:00:00 2001 From: Felix Lisczyk <5102728+FelixLisczyk@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:10:14 +0100 Subject: [PATCH] Add allKeys getter --- Sources/LRUCache.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sources/LRUCache.swift b/Sources/LRUCache.swift index f193864..1ed9a19 100644 --- a/Sources/LRUCache.swift +++ b/Sources/LRUCache.swift @@ -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()