/opt/canhelp/node_modules/next/dist/server/lib/cache-handlers
Edit: /opt/canhelp/node_modules/next/dist/server/lib/cache-handlers/default.external.js.map (7616B)
{"version":3,"sources":["../../../../src/server/lib/cache-handlers/default.external.ts"],"sourcesContent":["/**\n * This is the default \"use cache\" handler it defaults to an in-memory store.\n * In-memory caches are fragile and should not use stale-while-revalidate\n * semantics on the caches because it's not worth warming up an entry that's\n * likely going to get evicted before we get to use it anyway. However, we also\n * don't want to reuse a stale entry for too long so stale entries should be\n * considered expired/missing in such cache handlers.\n */\n\nimport { LRUCache } from '../lru-cache'\nimport type { CacheEntry, CacheHandlerV2 } from './types'\nimport {\n isStale,\n tagsManifest,\n} from '../incremental-cache/tags-manifest.external'\n\ntype PrivateCacheEntry = {\n entry: CacheEntry\n\n // For the default cache we store errored cache\n // entries and allow them to be used up to 3 times\n // after that we want to dispose it and try for fresh\n\n // If an entry is errored we return no entry\n // three times so that we retry hitting origin (MISS)\n // and then if it still fails to set after the third we\n // return the errored content and use expiration of\n // Math.min(30, entry.expiration)\n isErrored: boolean\n errorRetryCount: number\n\n // compute size on set since we need to read size\n // of the ReadableStream for LRU evicting\n size: number\n}\n\n// LRU cache default to max 50 MB but in future track\nconst memoryCache = new LRUCache
(\n 50 * 1024 * 1024,\n (entry) => entry.size\n)\nconst pendingSets = new Map>()\n\nconst debug = process.env.NEXT_PRIVATE_DEBUG_CACHE\n ? console.debug.bind(console, 'DefaultCacheHandler:')\n : undefined\n\nconst DefaultCacheHandler: CacheHandlerV2 = {\n async get(cacheKey) {\n const pendingPromise = pendingSets.get(cacheKey)\n\n if (pendingPromise) {\n debug?.('get', cacheKey, 'pending')\n await pendingPromise\n }\n\n const privateEntry = memoryCache.get(cacheKey)\n\n if (!privateEntry) {\n debug?.('get', cacheKey, 'not found')\n return undefined\n }\n\n const entry = privateEntry.entry\n if (\n performance.timeOrigin + performance.now() >\n entry.timestamp + entry.revalidate * 1000\n ) {\n // In-memory caches should expire after revalidate time because it is\n // unlikely that a new entry will be able to be used before it is dropped\n // from the cache.\n debug?.('get', cacheKey, 'expired')\n\n return undefined\n }\n\n if (isStale(entry.tags, entry.timestamp)) {\n debug?.('get', cacheKey, 'had stale tag')\n\n return undefined\n }\n const [returnStream, newSaved] = entry.value.tee()\n entry.value = newSaved\n\n debug?.('get', cacheKey, 'found', {\n tags: entry.tags,\n timestamp: entry.timestamp,\n revalidate: entry.revalidate,\n expire: entry.expire,\n })\n\n return {\n ...entry,\n value: returnStream,\n }\n },\n\n async set(cacheKey, pendingEntry) {\n debug?.('set', cacheKey, 'start')\n\n let resolvePending: () => void = () => {}\n const pendingPromise = new Promise((resolve) => {\n resolvePending = resolve\n })\n pendingSets.set(cacheKey, pendingPromise)\n\n const entry = await pendingEntry\n\n let size = 0\n\n try {\n const [value, clonedValue] = entry.value.tee()\n entry.value = value\n const reader = clonedValue.getReader()\n\n for (let chunk; !(chunk = await reader.read()).done; ) {\n size += Buffer.from(chunk.value).byteLength\n }\n\n memoryCache.set(cacheKey, {\n entry,\n isErrored: false,\n errorRetryCount: 0,\n size,\n })\n\n debug?.('set', cacheKey, 'done')\n } catch (err) {\n // TODO: store partial buffer with error after we retry 3 times\n debug?.('set', cacheKey, 'failed', err)\n } finally {\n resolvePending()\n pendingSets.delete(cacheKey)\n }\n },\n\n async refreshTags() {\n // Nothing to do for an in-memory cache handler.\n },\n\n async getExpiration(...tags) {\n const expiration = Math.max(\n ...tags.map((tag) => tagsManifest.get(tag) ?? 0)\n )\n\n debug?.('getExpiration', { tags, expiration })\n\n return expiration\n },\n\n async expireTags(...tags) {\n const timestamp = Math.round(performance.timeOrigin + performance.now())\n debug?.('expireTags', { tags, timestamp })\n\n for (const tag of tags) {\n // TODO: update file-system-cache?\n tagsManifest.set(tag, timestamp)\n }\n },\n}\n\nexport default DefaultCacheHandler\n"],"names":["memoryCache","LRUCache","entry","size","pendingSets","Map","debug","process","env","NEXT_PRIVATE_DEBUG_CACHE","console","bind","undefined","DefaultCacheHandler","get","cacheKey","pendingPromise","privateEntry","performance","timeOrigin","now","timestamp","revalidate","isStale","tags","returnStream","newSaved","value","tee","expire","set","pendingEntry","resolvePending","Promise","resolve","clonedValue","reader","getReader","chunk","read","done","Buffer","from","byteLength","isErrored","errorRetryCount","err","delete","refreshTags","getExpiration","expiration","Math","max","map","tag","tagsManifest","expireTags","round"],"mappings":"AAAA;;;;;;;CAOC;;;;+BA0JD;;;eAAA;;;0BAxJyB;sCAKlB;AAsBP,qDAAqD;AACrD,MAAMA,cAAc,IAAIC,kBAAQ,CAC9B,KAAK,OAAO,MACZ,CAACC,QAAUA,MAAMC,IAAI;AAEvB,MAAMC,cAAc,IAAIC;AAExB,MAAMC,QAAQC,QAAQC,GAAG,CAACC,wBAAwB,GAC9CC,QAAQJ,KAAK,CAACK,IAAI,CAACD,SAAS,0BAC5BE;AAEJ,MAAMC,sBAAsC;IAC1C,MAAMC,KAAIC,QAAQ;QAChB,MAAMC,iBAAiBZ,YAAYU,GAAG,CAACC;QAEvC,IAAIC,gBAAgB;YAClBV,yBAAAA,MAAQ,OAAOS,UAAU;YACzB,MAAMC;QACR;QAEA,MAAMC,eAAejB,YAAYc,GAAG,CAACC;QAErC,IAAI,CAACE,cAAc;YACjBX,yBAAAA,MAAQ,OAAOS,UAAU;YACzB,OAAOH;QACT;QAEA,MAAMV,QAAQe,aAAaf,KAAK;QAChC,IACEgB,YAAYC,UAAU,GAAGD,YAAYE,GAAG,KACxClB,MAAMmB,SAAS,GAAGnB,MAAMoB,UAAU,GAAG,MACrC;YACA,qEAAqE;YACrE,yEAAyE;YACzE,kBAAkB;YAClBhB,yBAAAA,MAAQ,OAAOS,UAAU;YAEzB,OAAOH;QACT;QAEA,IAAIW,IAAAA,6BAAO,EAACrB,MAAMsB,IAAI,EAAEtB,MAAMmB,SAAS,GAAG;YACxCf,yBAAAA,MAAQ,OAAOS,UAAU;YAEzB,OAAOH;QACT;QACA,MAAM,CAACa,cAAcC,SAAS,GAAGxB,MAAMyB,KAAK,CAACC,GAA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