MCPcopy
hub / github.com/webpack/webpack / parseCacheControl

Function parseCacheControl

lib/schemes/HttpUriPlugin.js:171–191  ·  view source on GitHub ↗
(cacheControl, requestTime)

Source from the content-addressed store, hash-verified

169 * @returns {{ storeCache: boolean, storeLock: boolean, validUntil: number }} Logic for storing in cache and lockfile cache
170 */
171const parseCacheControl = (cacheControl, requestTime) => {
172 // When false resource is not stored in cache
173 let storeCache = true;
174 // When false resource is not stored in lockfile cache
175 let storeLock = true;
176 // Resource is only revalidated, after that timestamp and when upgrade is chosen
177 let validUntil = 0;
178 if (cacheControl) {
179 const parsed = parseKeyValuePairs(cacheControl);
180 if (parsed["no-cache"]) storeCache = storeLock = false;
181 if (parsed["max-age"] && !Number.isNaN(Number(parsed["max-age"]))) {
182 validUntil = requestTime + Number(parsed["max-age"]) * 1000;
183 }
184 if (parsed["must-revalidate"]) validUntil = 0;
185 }
186 return {
187 storeLock,
188 storeCache,
189 validUntil
190 };
191};
192
193/**
194 * Defines the lockfile entry type used by this module.

Callers 1

fetchContentRawMethod · 0.85

Calls 1

parseKeyValuePairsFunction · 0.85

Tested by

no test coverage detected