@@ -62,6 +62,8 @@ export class Cache<T> {
6262 *
6363 * @param key - The key associated with the data to be cached.
6464 * @param data - The data to be cached.
65+ *
66+ * @throws {Error } If the key is empty, not a string, or longer than 255 characters.
6567 */
6668 set ( key : string , data : T ) : void {
6769 if ( ! key || typeof key !== 'string' || key . length > 255 ) {
@@ -127,6 +129,10 @@ export class Cache<T> {
127129 this . cache . delete ( key ) ;
128130 }
129131
132+ /**
133+ * Removes expired entries from the cache.
134+ * This method is called periodically by the cleanup interval.
135+ */
130136 private cleanup ( ) : void {
131137 const now = Date . now ( ) ;
132138
@@ -137,6 +143,11 @@ export class Cache<T> {
137143 }
138144 }
139145
146+ /**
147+ * Finds the key of the oldest entry in the cache based on timestamp.
148+ *
149+ * @returns The key of the oldest entry, or undefined if the cache is empty.
150+ */
140151 private findOldestEntry ( ) : string | undefined {
141152 let oldestKey : string | undefined ;
142153 let oldestTime = Infinity ;
@@ -169,6 +180,10 @@ type CacheEntry<T> = {
169180 * This value represents 1 hour.
170181 */
171182const DEFAULT_CACHE_TTL = 60 * 60 * 1000 ; // 1 hour in milliseconds
183+ /**
184+ * The default maximum number of entries the cache can hold.
185+ * This value represents 50 entries.
186+ */
172187const DEFAULT_MAX_CACHE_SIZE = 50 ;
173188
174189/**
@@ -178,7 +193,7 @@ const DEFAULT_MAX_CACHE_SIZE = 50;
178193 * @property {number } [maxSize] - The maximum number of entries that the cache can hold.
179194 */
180195
181- interface CacheConfig {
196+ export interface CacheConfig {
182197 timeToLive ?: number ;
183198 maxSize ?: number ;
184199}
0 commit comments