File tree Expand file tree Collapse file tree 2 files changed +50
-7
lines changed
packages/gitbook-v2/openNext/tagCache Expand file tree Collapse file tree 2 files changed +50
-7
lines changed Original file line number Diff line number Diff line change
1
+ import type { NextModeTagCache } from '@opennextjs/aws/types/overrides.js' ;
1
2
import doShardedTagCache from '@opennextjs/cloudflare/overrides/tag-cache/do-sharded-tag-cache' ;
2
3
import {
3
4
softTagFilter ,
4
5
withFilter ,
5
6
} from '@opennextjs/cloudflare/overrides/tag-cache/tag-cache-filter' ;
6
7
7
- export default withFilter ( {
8
+ const filteredTagCache = withFilter ( {
8
9
tagCache : doShardedTagCache ( {
9
10
baseShardSize : 12 ,
10
11
regionalCache : true ,
@@ -16,3 +17,31 @@ export default withFilter({
16
17
// We don't use `revalidatePath`, so we filter out soft tags
17
18
filterFn : softTagFilter ,
18
19
} ) ;
20
+
21
+ export default {
22
+ name : 'GitbookTagCache' ,
23
+ mode : 'nextMode' ,
24
+ getLastRevalidated : async ( tags : string [ ] ) => {
25
+ try {
26
+ return await filteredTagCache . getLastRevalidated ( tags ) ;
27
+ } catch ( error ) {
28
+ console . error ( 'Error getting last revalidated tags:' , error ) ;
29
+ return 0 ; // Fallback to 0 if there's an error
30
+ }
31
+ } ,
32
+ hasBeenRevalidated : async ( tags : string [ ] ) => {
33
+ try {
34
+ return await filteredTagCache . hasBeenRevalidated ( tags ) ;
35
+ } catch ( error ) {
36
+ console . error ( 'Error checking if tags have been revalidated:' , error ) ;
37
+ return false ; // Fallback to false if there's an error
38
+ }
39
+ } ,
40
+ writeTags : async ( tags : string [ ] ) => {
41
+ try {
42
+ await filteredTagCache . writeTags ( tags ) ;
43
+ } catch ( error ) {
44
+ console . error ( 'Error writing tags:' , error ) ;
45
+ }
46
+ } ,
47
+ } satisfies NextModeTagCache ;
Original file line number Diff line number Diff line change @@ -12,15 +12,29 @@ export default {
12
12
name : 'GitbookTagCache' ,
13
13
mode : 'nextMode' ,
14
14
getLastRevalidated : async ( tags : string [ ] ) => {
15
- const { env } = getCloudflareContext ( ) ;
16
- return ( env as Env ) . MIDDLEWARE_REFERENCE ?. getLastRevalidated ( tags ) ?? 0 ;
15
+ try {
16
+ const { env } = getCloudflareContext ( ) ;
17
+ return ( env as Env ) . MIDDLEWARE_REFERENCE ?. getLastRevalidated ( tags ) ?? 0 ;
18
+ } catch ( error ) {
19
+ console . error ( 'Server - Error getting last revalidated tags:' , error ) ;
20
+ return 0 ; // Fallback to 0 if there's an error
21
+ }
17
22
} ,
18
23
hasBeenRevalidated : async ( tags : string [ ] ) => {
19
- const { env } = getCloudflareContext ( ) ;
20
- return ( env as Env ) . MIDDLEWARE_REFERENCE ?. hasBeenRevalidated ( tags ) ?? false ;
24
+ try {
25
+ const { env } = getCloudflareContext ( ) ;
26
+ return ( env as Env ) . MIDDLEWARE_REFERENCE ?. hasBeenRevalidated ( tags ) ?? false ;
27
+ } catch ( error ) {
28
+ console . error ( 'Server - Error checking if tags have been revalidated:' , error ) ;
29
+ return false ; // Fallback to false if there's an error
30
+ }
21
31
} ,
22
32
writeTags : async ( tags : string [ ] ) => {
23
- const { env } = getCloudflareContext ( ) ;
24
- ( env as Env ) . MIDDLEWARE_REFERENCE ?. writeTags ( tags ) ;
33
+ try {
34
+ const { env } = getCloudflareContext ( ) ;
35
+ ( env as Env ) . MIDDLEWARE_REFERENCE ?. writeTags ( tags ) ;
36
+ } catch ( error ) {
37
+ console . error ( 'Server - Error writing tags:' , error ) ;
38
+ }
25
39
} ,
26
40
} satisfies NextModeTagCache ;
You can’t perform that action at this time.
0 commit comments