@@ -2,13 +2,9 @@ import { getStore } from '@netlify/blobs'
2
2
import { purgeCache } from '@netlify/functions'
3
3
import type { CacheHandler , CacheHandlerContext } from 'next/dist/server/lib/incremental-cache/index.js'
4
4
5
- type TagsManifest = {
6
- version : 1
7
- items : { [ tag : string ] : { revalidatedAt : number } }
8
- }
5
+ type TagManifest = { revalidatedAt : number }
9
6
10
- let tagsManifest : TagsManifest | undefined
11
- const tagsManifestPath = '_netlify/tags-manifest.json'
7
+ const tagsManifestPath = '_netlify-cache/tags'
12
8
const blobStore = getStore ( 'TODO' )
13
9
14
10
/**
@@ -17,11 +13,11 @@ const blobStore = getStore('TODO')
17
13
*/
18
14
export default class NetlifyCacheHandler implements CacheHandler {
19
15
options : CacheHandlerContext
16
+ revalidatedTags : string [ ]
20
17
21
18
constructor ( options : CacheHandlerContext ) {
22
19
this . options = options
23
-
24
- this . loadTagsManifest ( )
20
+ this . revalidatedTags = options . revalidatedTags
25
21
}
26
22
27
23
// eslint-disable-next-line require-await, class-methods-use-this
@@ -39,31 +35,29 @@ export default class NetlifyCacheHandler implements CacheHandler {
39
35
public async revalidateTag ( tag : string ) {
40
36
console . log ( 'NetlifyCacheHandler.revalidateTag' , tag )
41
37
42
- await this . loadTagsManifest ( )
43
- if ( ! tagsManifest ) {
44
- return
38
+ const data : TagManifest = {
39
+ revalidatedAt : Date . now ( )
45
40
}
46
41
47
- const data = tagsManifest . items [ tag ] || { }
48
- data . revalidatedAt = Date . now ( )
49
- tagsManifest . items [ tag ] = data
50
-
51
42
try {
52
- blobStore . setJSON ( tagsManifestPath , tagsManifest )
43
+ blobStore . setJSON ( this . tagManifestPath ( tag ) , data )
53
44
} catch ( error : any ) {
54
- console . warn ( ' Failed to update tags manifest.' , error )
45
+ console . warn ( ` Failed to update tag manifest for ${ tag } ` , error )
55
46
}
56
47
57
48
purgeCache ( { tags : [ tag ] } )
58
49
}
59
50
60
- // eslint-disable-next-line class-methods-use-this
61
- private async loadTagsManifest ( ) {
51
+ private async loadTagManifest ( tag : string ) {
62
52
try {
63
- tagsManifest = await blobStore . get ( tagsManifestPath , { type : 'json' } )
53
+ return await blobStore . get ( this . tagManifestPath ( tag ) , { type : 'json' } )
64
54
} catch ( error : any ) {
65
- console . warn ( 'Failed to fetch tags manifest.' , error )
66
- tagsManifest = { version : 1 , items : { } }
55
+ console . warn ( `Failed to fetch tag manifest for ${ tag } ` , error )
67
56
}
68
57
}
58
+
59
+ // eslint-disable-next-line class-methods-use-this
60
+ private tagManifestPath ( tag : string ) {
61
+ return [ tagsManifestPath , tag ] . join ( '/' )
62
+ }
69
63
}
0 commit comments