(cacheControl, requestTime)
| 169 | * @returns {{ storeCache: boolean, storeLock: boolean, validUntil: number }} Logic for storing in cache and lockfile cache |
| 170 | */ |
| 171 | const 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. |
no test coverage detected