@@ -2,13 +2,15 @@ import FileSystemCache from 'next/dist/server/lib/incremental-cache/file-system-
2
2
import { LRUCache } from 'lru-cache' ;
3
3
import { CacheHandlerValue } from 'next/dist/server/lib/incremental-cache' ;
4
4
import { nodeFs } from 'next/dist/server/lib/node-fs-methods' ;
5
- import { redisClient } from './redis' ;
5
+ import { RedisCache } from './redis' ;
6
6
7
7
type FileSystemCacheContext = ConstructorParameters < typeof FileSystemCache > [ 0 ] ;
8
8
9
9
const CACHE_TTL_24_HOURS = 3600 * 24 * 1000 ;
10
10
11
- const isrMemoryCache = new LRUCache < string , CacheHandlerValue > ( {
11
+ export const redisCache = new RedisCache ( { ttl : CACHE_TTL_24_HOURS } ) ;
12
+
13
+ const localCache = new LRUCache < string , CacheHandlerValue > ( {
12
14
max : 1000 ,
13
15
ttl : CACHE_TTL_24_HOURS ,
14
16
ttlResolution : 1000 ,
@@ -33,9 +35,7 @@ export default class CustomFileSystemCache extends FileSystemCache {
33
35
public async get ( ...args : Parameters < FileSystemCache [ 'get' ] > ) {
34
36
const [ key ] = args ;
35
37
36
- console . log ( `Getting from cache: ${ key } ` ) ;
37
-
38
- const foundData = await redisClient . get ( key ) ;
38
+ const foundData = await redisCache . get ( key ) ;
39
39
40
40
if ( ! foundData ?. value ) {
41
41
return null ;
@@ -69,26 +69,26 @@ export default class CustomFileSystemCache extends FileSystemCache {
69
69
public async set ( ...args : Parameters < FileSystemCache [ 'set' ] > ) {
70
70
const [ key , data ] = args ;
71
71
72
- console . log ( `Storing in cache: ${ key } ` ) ;
73
-
74
72
const cacheItem : CacheHandlerValue = {
75
73
value : data ,
76
74
lastModified : Date . now ( ) ,
77
75
} ;
78
76
79
- redisClient . set ( key , cacheItem ) ;
77
+ redisCache
78
+ . set ( key , cacheItem )
79
+ . then ( ( result ) => console . log ( `Set key ${ key } result` , result ) ) ;
80
80
81
81
// isrMemoryCache.set(key, { value: data, lastModified: Date.now() });
82
82
// return super.set(...args);
83
83
}
84
84
85
85
public async clearGlobalCache ( ) {
86
- isrMemoryCache . clear ( ) ;
86
+ localCache . clear ( ) ;
87
87
return true ;
88
88
}
89
89
90
90
public async deleteGlobalCacheEntry ( path : string ) {
91
91
const pagePath = path === '/' ? '/index' : path ;
92
- return isrMemoryCache . delete ( pagePath ) ;
92
+ return localCache . delete ( pagePath ) ;
93
93
}
94
94
}
0 commit comments