Skip to content

Commit 566633d

Browse files
committed
📚 Update docs (#1995)
1 parent a627659 commit 566633d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/lib/clients/aizu_online_judge.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,8 @@ export class AojApiClient extends ContestSiteApiClient {
142142
* Constructs an instance of the Aizu Online Judge client.
143143
*
144144
* @param {ApiClientConfig} [config] - Optional configuration object for the API client.
145-
* @param {Cache<ContestsForImport>} [config.contestCache] - Configuration for the contest cache.
146-
* @param {number} [config.contestCache.timeToLive] - Time to live for contest cache entries.
147-
* @param {number} [config.contestCache.maxSize] - Maximum size of the contest cache.
148-
* @param {Cache<TasksForImport>} [config.taskCache] - Configuration for the task cache.
149-
* @param {number} [config.taskCache.timeToLive] - Time to live for task cache entries.
150-
* @param {number} [config.taskCache.maxSize] - Maximum size of the task cache.
145+
* @param {CacheConfig} [config.contestCache] - Configuration for the contest cache.
146+
* @param {CacheConfig} [config.taskCache] - Configuration for the task cache.
151147
*/
152148
constructor(config?: ApiClientConfig) {
153149
super();

src/lib/clients/cache.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
*/
171182
const 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+
*/
172187
const 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

Comments
 (0)