Skip to content

Commit e6a48f4

Browse files
committed
✨ Add cache helper (#1995)
1 parent 451c7fc commit e6a48f4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/lib/clients/cache.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ export class Cache<T> {
8181
this.cache.set(key, { data, timestamp: Date.now() });
8282
}
8383

84+
/**
85+
* Checks if a key exists in the cache without removing expired entries.
86+
*
87+
* @param key - The key to check.
88+
* @returns True if the key exists in the cache, false otherwise.
89+
*/
90+
has(key: string): boolean {
91+
return this.cache.has(key);
92+
}
93+
8494
/**
8595
* Retrieves an entry from the cache.
8696
*
@@ -106,7 +116,7 @@ export class Cache<T> {
106116
* Disposes of resources used by the cache instance.
107117
*
108118
* This method clears the interval used for cleanup and clears the cache.
109-
* It should be called when the client is no longer needed to prevent memory leaks.
119+
* It should be called when the cache instance is no longer needed to prevent memory leaks.
110120
*/
111121
dispose(): void {
112122
clearInterval(this.cleanupInterval);

0 commit comments

Comments
 (0)