@@ -5,7 +5,7 @@ import { Buffer } from 'node:buffer'
5
5
import { readFileSync } from 'node:fs'
6
6
import { join } from 'node:path/posix'
7
7
8
- import { getDeployStore } from '@netlify/blobs'
8
+ import { getDeployStore , Store } from '@netlify/blobs'
9
9
import { purgeCache } from '@netlify/functions'
10
10
import type { PrerenderManifest } from 'next/dist/build/index.js'
11
11
import { NEXT_CACHE_TAGS_HEADER } from 'next/dist/lib/constants.js'
@@ -20,8 +20,6 @@ import type { CacheEntry } from '../../build/plugin-context.ts'
20
20
21
21
type TagManifest = { revalidatedAt : number }
22
22
23
- export const blobStore = getDeployStore ( )
24
-
25
23
// load the prerender manifest
26
24
const prerenderManifest : PrerenderManifest = JSON . parse (
27
25
readFileSync ( join ( process . cwd ( ) , '.next/prerender-manifest.json' ) , 'utf-8' ) ,
@@ -39,18 +37,20 @@ function encodeBlobKey(key: string) {
39
37
export class NetlifyCacheHandler implements CacheHandler {
40
38
options : CacheHandlerContext
41
39
revalidatedTags : string [ ]
40
+ blobStore : Store
42
41
43
42
constructor ( options : CacheHandlerContext ) {
44
43
this . options = options
45
44
this . revalidatedTags = options . revalidatedTags
45
+ this . blobStore = getDeployStore ( )
46
46
}
47
47
48
48
async get ( ...args : Parameters < CacheHandler [ 'get' ] > ) : ReturnType < CacheHandler [ 'get' ] > {
49
49
const [ key , ctx = { } ] = args
50
50
51
51
console . debug ( `[NetlifyCacheHandler.get]: ${ key } ` )
52
52
53
- const blob = ( await blobStore . get ( encodeBlobKey ( key ) , {
53
+ const blob = ( await this . blobStore . get ( encodeBlobKey ( key ) , {
54
54
type : 'json' ,
55
55
} ) ) as CacheEntry | null
56
56
@@ -104,7 +104,7 @@ export class NetlifyCacheHandler implements CacheHandler {
104
104
105
105
console . debug ( `[NetlifyCacheHandler.set]: ${ key } ` )
106
106
107
- await blobStore . setJSON ( encodeBlobKey ( key ) , {
107
+ await this . blobStore . setJSON ( encodeBlobKey ( key ) , {
108
108
lastModified : Date . now ( ) ,
109
109
value : data ,
110
110
} )
@@ -119,7 +119,7 @@ export class NetlifyCacheHandler implements CacheHandler {
119
119
}
120
120
121
121
try {
122
- await blobStore . setJSON ( encodeBlobKey ( tag ) , data )
122
+ await this . blobStore . setJSON ( encodeBlobKey ( tag ) , data )
123
123
} catch ( error ) {
124
124
console . warn ( `Failed to update tag manifest for ${ tag } ` , error )
125
125
}
@@ -142,7 +142,7 @@ export class NetlifyCacheHandler implements CacheHandler {
142
142
const cacheTags = [ ...tags , ...softTags ]
143
143
const allManifests = await Promise . all (
144
144
cacheTags . map ( async ( tag ) => {
145
- const res = await blobStore
145
+ const res = await this . blobStore
146
146
. get ( encodeBlobKey ( tag ) , { type : 'json' } )
147
147
. then ( ( value : TagManifest ) => ( { [ tag ] : value } ) )
148
148
. catch ( console . error )
0 commit comments