🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@netlify/cache

Package Overview
Dependencies
Maintainers
19
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netlify/cache - npm Package Compare versions

Comparing version
3.3.5
to
3.4.0
+41
-0
dist/main.cjs

@@ -32,2 +32,3 @@ "use strict";

getCacheStatus: () => getCacheStatus,
needsRevalidation: () => needsRevalidation,
setCacheHeaders: () => setCacheHeaders

@@ -270,2 +271,15 @@ });

};
var needsRevalidation = (response) => {
const header = response.headers.get(CacheStatus);
if (!header) {
return false;
}
for (const value of header.split(",")) {
const { attributes, name } = parseCacheStatusValue(value);
if (name === CACHE_DURABLE && attributes.detail === "client-revalidate") {
return true;
}
}
return false;
};
var getCacheStatus = (input) => {

@@ -341,2 +355,15 @@ if (typeof input === "string") {

if (cached) {
if (needsRevalidation(cached)) {
const { fetch: fetchFn = globalThis.fetch } = cacheOptions;
const revalidation = performBackgroundRevalidation(request, cache, cacheSettings, fetchFn);
if (onCachePut) {
await onCachePut(revalidation);
} else {
const netlifyGlobal = globalThis.Netlify;
const requestContext = netlifyGlobal?.context;
if (requestContext) {
requestContext.waitUntil(revalidation);
}
}
}
return cached;

@@ -368,2 +395,15 @@ }

};
var performBackgroundRevalidation = async (request, cache, cacheSettings, fetchFn) => {
try {
const fresh = await fetchFn(request);
if (!fresh.body) {
return;
}
const cacheResponse = new Response(fresh.body, fresh);
applyHeaders(cacheResponse.headers, cacheHeaders(cacheSettings));
await cache.put(request, cacheResponse);
} catch (error) {
console.warn("`fetchWithCache` has failed to revalidate a stale response:", error);
}
};

@@ -387,3 +427,4 @@ // src/constants.ts

getCacheStatus,
needsRevalidation,
setCacheHeaders
});
+10
-1

@@ -133,2 +133,11 @@ import { N as NetlifyCache } from './cache-B9TsVKLp.cjs';

/**
* Returns whether a cached response includes a signal that the client should
* perform a background revalidation. This may happen when using the Cache API
* with the `stale-while-revalidate` directive, since unlike the regular cache,
* the client is the one responsible for explicitly inserting new entries into
* the cache. So when this returns `true`, the caller should fetch the resource
* and write the fresh response back to the cache with `cache.put()`.
*/
declare const needsRevalidation: (response: Response) => boolean;
/**
* Retrieves information about how a response has interacted with Netlify's

@@ -197,2 +206,2 @@ * global caching infrastructure, including whether the response has been

export { DAY, HOUR, MINUTE, WEEK, YEAR, cacheHeaders, caches, fetchWithCache, getCacheStatus, setCacheHeaders };
export { DAY, HOUR, MINUTE, WEEK, YEAR, cacheHeaders, caches, fetchWithCache, getCacheStatus, needsRevalidation, setCacheHeaders };

@@ -133,2 +133,11 @@ import { N as NetlifyCache } from './cache-B9TsVKLp.js';

/**
* Returns whether a cached response includes a signal that the client should
* perform a background revalidation. This may happen when using the Cache API
* with the `stale-while-revalidate` directive, since unlike the regular cache,
* the client is the one responsible for explicitly inserting new entries into
* the cache. So when this returns `true`, the caller should fetch the resource
* and write the fresh response back to the cache with `cache.put()`.
*/
declare const needsRevalidation: (response: Response) => boolean;
/**
* Retrieves information about how a response has interacted with Netlify's

@@ -197,2 +206,2 @@ * global caching infrastructure, including whether the response has been

export { DAY, HOUR, MINUTE, WEEK, YEAR, cacheHeaders, caches, fetchWithCache, getCacheStatus, setCacheHeaders };
export { DAY, HOUR, MINUTE, WEEK, YEAR, cacheHeaders, caches, fetchWithCache, getCacheStatus, needsRevalidation, setCacheHeaders };

@@ -234,2 +234,15 @@ // src/polyfill.ts

};
var needsRevalidation = (response) => {
const header = response.headers.get(CacheStatus);
if (!header) {
return false;
}
for (const value of header.split(",")) {
const { attributes, name } = parseCacheStatusValue(value);
if (name === CACHE_DURABLE && attributes.detail === "client-revalidate") {
return true;
}
}
return false;
};
var getCacheStatus = (input) => {

@@ -305,2 +318,15 @@ if (typeof input === "string") {

if (cached) {
if (needsRevalidation(cached)) {
const { fetch: fetchFn = globalThis.fetch } = cacheOptions;
const revalidation = performBackgroundRevalidation(request, cache, cacheSettings, fetchFn);
if (onCachePut) {
await onCachePut(revalidation);
} else {
const netlifyGlobal = globalThis.Netlify;
const requestContext = netlifyGlobal?.context;
if (requestContext) {
requestContext.waitUntil(revalidation);
}
}
}
return cached;

@@ -332,2 +358,15 @@ }

};
var performBackgroundRevalidation = async (request, cache, cacheSettings, fetchFn) => {
try {
const fresh = await fetchFn(request);
if (!fresh.body) {
return;
}
const cacheResponse = new Response(fresh.body, fresh);
applyHeaders(cacheResponse.headers, cacheHeaders(cacheSettings));
await cache.put(request, cacheResponse);
} catch (error) {
console.warn("`fetchWithCache` has failed to revalidate a stale response:", error);
}
};

@@ -350,3 +389,4 @@ // src/constants.ts

getCacheStatus,
needsRevalidation,
setCacheHeaders
};
+1
-1
{
"name": "@netlify/cache",
"version": "3.3.5",
"version": "3.4.0",
"description": "TypeScript utilities for interacting with the Netlify cache",

@@ -5,0 +5,0 @@ "type": "module",