File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
packages/cloudflare/src/api/overrides/incremental-cache Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -143,10 +143,18 @@ class RegionalCache implements IncrementalCache {
143143 ? ONE_MINUTE_IN_SECONDS
144144 : entry . value . revalidate || THIRTY_MINUTES_IN_SECONDS ;
145145
146+ const tags = getTagsFromCacheEntry ( entry ) ;
146147 await cache . put (
147148 key ,
148149 new Response ( JSON . stringify ( entry ) , {
149- headers : new Headers ( { "cache-control" : `max-age=${ age } ` } ) ,
150+ headers : new Headers ( {
151+ "cache-control" : `max-age=${ age } ` ,
152+ ...( tags . length > 0
153+ ? {
154+ "cache-tag" : tags . join ( "," ) ,
155+ }
156+ : { } ) ,
157+ } ) ,
150158 } )
151159 ) ;
152160 }
@@ -175,3 +183,25 @@ class RegionalCache implements IncrementalCache {
175183export function withRegionalCache ( cache : IncrementalCache , opts : Options ) {
176184 return new RegionalCache ( cache , opts ) ;
177185}
186+
187+ /**
188+ * Extract the list of tags from a cache entry.
189+ */
190+ export function getTagsFromCacheEntry ( entry : IncrementalCacheEntry < boolean > ) : string [ ] {
191+ if ( "tags" in entry . value && entry . value . tags ) {
192+ return entry . value . tags ;
193+ }
194+
195+ if (
196+ "meta" in entry . value &&
197+ entry . value . meta &&
198+ "headers" in entry . value . meta &&
199+ entry . value . meta . headers
200+ ) {
201+ const rawTags = entry . value . meta . headers [ "x-next-cache-tags" ] ;
202+ if ( typeof rawTags === "string" ) {
203+ return rawTags . split ( "," ) ;
204+ }
205+ }
206+ return [ ] ;
207+ }
You can’t perform that action at this time.
0 commit comments