@@ -2,13 +2,9 @@ import { getStore } from '@netlify/blobs'
22import { purgeCache } from '@netlify/functions'
33import type { CacheHandler , CacheHandlerContext } from 'next/dist/server/lib/incremental-cache/index.js'
44
5- type TagsManifest = {
6- version : 1
7- items : { [ tag : string ] : { revalidatedAt : number } }
8- }
5+ type TagManifest = { revalidatedAt : number }
96
10- let tagsManifest : TagsManifest | undefined
11- const tagsManifestPath = '_netlify/tags-manifest.json'
7+ const tagsManifestPath = '_netlify-cache/tags'
128const blobStore = getStore ( 'TODO' )
139
1410/**
@@ -17,11 +13,11 @@ const blobStore = getStore('TODO')
1713 */
1814export default class NetlifyCacheHandler implements CacheHandler {
1915 options : CacheHandlerContext
16+ revalidatedTags : string [ ]
2017
2118 constructor ( options : CacheHandlerContext ) {
2219 this . options = options
23-
24- this . loadTagsManifest ( )
20+ this . revalidatedTags = options . revalidatedTags
2521 }
2622
2723 // eslint-disable-next-line require-await, class-methods-use-this
@@ -39,31 +35,29 @@ export default class NetlifyCacheHandler implements CacheHandler {
3935 public async revalidateTag ( tag : string ) {
4036 console . log ( 'NetlifyCacheHandler.revalidateTag' , tag )
4137
42- await this . loadTagsManifest ( )
43- if ( ! tagsManifest ) {
44- return
38+ const data : TagManifest = {
39+ revalidatedAt : Date . now ( )
4540 }
4641
47- const data = tagsManifest . items [ tag ] || { }
48- data . revalidatedAt = Date . now ( )
49- tagsManifest . items [ tag ] = data
50-
5142 try {
52- blobStore . setJSON ( tagsManifestPath , tagsManifest )
43+ blobStore . setJSON ( this . tagManifestPath ( tag ) , data )
5344 } catch ( error : any ) {
54- console . warn ( ' Failed to update tags manifest.' , error )
45+ console . warn ( ` Failed to update tag manifest for ${ tag } ` , error )
5546 }
5647
5748 purgeCache ( { tags : [ tag ] } )
5849 }
5950
60- // eslint-disable-next-line class-methods-use-this
61- private async loadTagsManifest ( ) {
51+ private async loadTagManifest ( tag : string ) {
6252 try {
63- tagsManifest = await blobStore . get ( tagsManifestPath , { type : 'json' } )
53+ return await blobStore . get ( this . tagManifestPath ( tag ) , { type : 'json' } )
6454 } 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 )
6756 }
6857 }
58+
59+ // eslint-disable-next-line class-methods-use-this
60+ private tagManifestPath ( tag : string ) {
61+ return [ tagsManifestPath , tag ] . join ( '/' )
62+ }
6963}
0 commit comments