@@ -74,7 +74,7 @@ export class RedisCacheHandler extends CacheHandler {
74
74
options .keyPrefix = options .keyPrefix || ' isr' ;
75
75
}
76
76
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 > {
78
78
const key = this .createKey (cacheKey );
79
79
const createdAt = Date .now ().toString ();
80
80
await this .redis .hmset (key , {
@@ -128,22 +128,6 @@ export class RedisCacheHandler extends CacheHandler {
128
128
return ` ${this .redisCacheOptions .keyPrefix }:${cacheKey } ` ;
129
129
}
130
130
}
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
- };
147
131
```
148
132
149
133
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:
197
181
198
182
``` typescript
199
183
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 >;
201
192
202
- abstract get(url : string ): Promise <CacheData >;
193
+ abstract get(cacheKey : string ): Promise <CacheData >;
203
194
204
- abstract getAll( ): Promise <string [] >;
195
+ abstract has( cacheKey : string ): Promise <boolean >;
205
196
206
- abstract has( url : string ): Promise <boolean >;
197
+ abstract delete( cacheKey : string ): Promise <boolean >;
207
198
208
- abstract delete( url : string ): Promise <boolean >;
199
+ abstract getAll( ): Promise <string [] >;
209
200
210
201
abstract clearCache? (): Promise <boolean >;
211
202
}
@@ -223,5 +214,5 @@ export interface CacheData {
223
214
}
224
215
```
225
216
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.
227
218
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