Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd14b62

Browse files
committed
docs(isr): update CacheHandler API doc
1 parent f7fb152 commit bd14b62

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

apps/docs/docs/isr/cache-handlers.md

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class RedisCacheHandler extends CacheHandler {
7474
options.keyPrefix = options.keyPrefix || 'isr';
7575
}
7676

77-
add(url: string, html: string | Buffer, options: ISROptions = { revalidate: null }): Promise<void> {
77+
add(cacheKey: string, html: string | Buffer, options: ISROptions = { revalidate: null }): Promise<void> {
7878
const key = this.createKey(cacheKey);
7979
const createdAt = Date.now().toString();
8080
await this.redis.hmset(key, {
@@ -128,22 +128,6 @@ export class RedisCacheHandler extends CacheHandler {
128128
return `${this.redisCacheOptions.keyPrefix}:${cacheKey}`;
129129
}
130130
}
131-
132-
const cacheMsg = (revalidateTime?: number | null): string => {
133-
const time = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
134-
135-
let msg = '<!-- ';
136-
137-
msg += `\n🚀 ISR: Served from Redis Cache! \n⌛ Last updated: ${time}. `;
138-
139-
if (revalidateTime) {
140-
msg += `\n⏭️ Next refresh is after ${revalidateTime} seconds. `;
141-
}
142-
143-
msg += ' \n-->';
144-
145-
return msg;
146-
};
147131
```
148132

149133
And then, to register the cache handler, you need to pass it to the `cache` field in ISRHandler:
@@ -197,15 +181,22 @@ The `CacheHandler` abstract class has the following API:
197181

198182
```typescript
199183
export abstract class CacheHandler {
200-
abstract add(url: string | Buffer, html: string, options: ISROptions): Promise<void>;
184+
// html could be a string or a buffer, it is depending on if `compressHtml` is set in `ISRHandler` config.
185+
// if `compressHtml` is set, the html will be a buffer, otherwise it will be a string
186+
abstract add(
187+
cacheKey: string,
188+
// it will be buffer when we use compressHtml
189+
html: string | Buffer,
190+
config?: CacheISRConfig,
191+
): Promise<void>;
201192

202-
abstract get(url: string): Promise<CacheData>;
193+
abstract get(cacheKey: string): Promise<CacheData>;
203194

204-
abstract getAll(): Promise<string[]>;
195+
abstract has(cacheKey: string): Promise<boolean>;
205196

206-
abstract has(url: string): Promise<boolean>;
197+
abstract delete(cacheKey: string): Promise<boolean>;
207198

208-
abstract delete(url: string): Promise<boolean>;
199+
abstract getAll(): Promise<string[]>;
209200

210201
abstract clearCache?(): Promise<boolean>;
211202
}
@@ -223,5 +214,5 @@ export interface CacheData {
223214
}
224215
```
225216

226-
note: The `html` field can be a string or a buffer. It depends on if you set `compressHtml` function in the `ISRHandler` options.
217+
**note**: The `html` field can be a string or a buffer. It depends on if you set `compressHtml` function in the `ISRHandler` options.
227218
If it is set, the html will be compressed and stored as a buffer. If it is not set, the html will be stored as a string.

0 commit comments

Comments
 (0)