From affd95f2ad932653ce1ce90c7ec841cdc777a4c3 Mon Sep 17 00:00:00 2001 From: Ryan Goree Date: Fri, 1 Mar 2024 00:57:54 -0600 Subject: [PATCH] Add `entries` property to `SimpleCache` type (#45) * Add `entries` property to `SimpleCache` type * Add changeset --- .changeset/heavy-tables-glow.md | 5 +++++ .../evm-client/src/cache/factories/createLruSimpleCache.ts | 4 ++++ packages/evm-client/src/cache/types/SimpleCache.ts | 5 +++++ 3 files changed, 14 insertions(+) create mode 100644 .changeset/heavy-tables-glow.md diff --git a/.changeset/heavy-tables-glow.md b/.changeset/heavy-tables-glow.md new file mode 100644 index 00000000..8acba531 --- /dev/null +++ b/.changeset/heavy-tables-glow.md @@ -0,0 +1,5 @@ +--- +"@delvtech/evm-client": patch +--- + +Add `entries` property to the `SimpleCache` type. diff --git a/packages/evm-client/src/cache/factories/createLruSimpleCache.ts b/packages/evm-client/src/cache/factories/createLruSimpleCache.ts index d5c8f7b0..1cb65af7 100644 --- a/packages/evm-client/src/cache/factories/createLruSimpleCache.ts +++ b/packages/evm-client/src/cache/factories/createLruSimpleCache.ts @@ -19,6 +19,10 @@ export function createLruSimpleCache< const cache = new LRUCache(options); return { + get entries() { + return cache.entries() as Generator<[TKey, TValue]>; + }, + get(key) { return cache.get(stringify(key)); }, diff --git a/packages/evm-client/src/cache/types/SimpleCache.ts b/packages/evm-client/src/cache/types/SimpleCache.ts index 1a63513e..001d6d04 100644 --- a/packages/evm-client/src/cache/types/SimpleCache.ts +++ b/packages/evm-client/src/cache/types/SimpleCache.ts @@ -10,6 +10,11 @@ export interface SimpleCache< TValue = any, TKey extends SimpleCacheKey = SimpleCacheKey, > { + /** + * Returns an iterable of key-value pairs for every entry in the cache. + */ + readonly entries: Iterable<[TKey, TValue]>; + /** * Retrieves the value associated with the specified key. */