| Server IP : 13.235.167.51 / Your IP : 216.73.217.116 Web Server : Apache System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64 User : root ( 0) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/control.machinox.in/node_modules/next/dist/esm/client/components/segment-cache/ |
Upload File : |
{"version":3,"sources":["../../../../../src/client/components/segment-cache/lru.ts"],"sourcesContent":["import { deleteMapEntry } from './cache-map'\nimport type { UnknownMapEntry } from './cache-map'\n\n// We use an LRU for memory management. We must update this whenever we add or\n// remove a new cache entry, or when an entry changes size.\n\nlet head: UnknownMapEntry | null = null\nlet didScheduleCleanup: boolean = false\nlet lruSize: number = 0\n\n// TODO: I chose the max size somewhat arbitrarily. Consider setting this based\n// on navigator.deviceMemory, or some other heuristic. We should make this\n// customizable via the Next.js config, too.\nconst maxLruSize = 50 * 1024 * 1024 // 50 MB\n\nexport function lruPut(node: UnknownMapEntry) {\n if (head === node) {\n // Already at the head\n return\n }\n const prev = node.prev\n const next = node.next\n if (next === null || prev === null) {\n // This is an insertion\n lruSize += node.size\n // Whenever we add an entry, we need to check if we've exceeded the\n // max size. We don't evict entries immediately; they're evicted later in\n // an asynchronous task.\n ensureCleanupIsScheduled()\n } else {\n // This is a move. Remove from its current position.\n prev.next = next\n next.prev = prev\n }\n\n // Move to the front of the list\n if (head === null) {\n // This is the first entry\n node.prev = node\n node.next = node\n } else {\n // Add to the front of the list\n const tail = head.prev\n node.prev = tail\n // In practice, this is never null, but that isn't encoded in the type\n if (tail !== null) {\n tail.next = node\n }\n node.next = head\n head.prev = node\n }\n head = node\n}\n\nexport function updateLruSize(node: UnknownMapEntry, newNodeSize: number) {\n // This is a separate function from `put` so that we can resize the entry\n // regardless of whether it's currently being tracked by the LRU.\n const prevNodeSize = node.size\n node.size = newNodeSize\n if (node.next === null) {\n // This entry is not currently being tracked by the LRU.\n return\n }\n // Update the total LRU size\n lruSize = lruSize - prevNodeSize + newNodeSize\n ensureCleanupIsScheduled()\n}\n\nexport function deleteFromLru(deleted: UnknownMapEntry) {\n const next = deleted.next\n const prev = deleted.prev\n if (next !== null && prev !== null) {\n lruSize -= deleted.size\n\n deleted.next = null\n deleted.prev = null\n\n // Remove from the list\n if (head === deleted) {\n // Update the head\n if (next === head) {\n // This was the last entry\n head = null\n } else {\n head = next\n }\n } else {\n prev.next = next\n next.prev = prev\n }\n } else {\n // Already deleted\n }\n}\n\nfunction ensureCleanupIsScheduled() {\n if (didScheduleCleanup || lruSize <= maxLruSize) {\n return\n }\n didScheduleCleanup = true\n requestCleanupCallback(cleanup)\n}\n\nfunction cleanup() {\n didScheduleCleanup = false\n\n // Evict entries until we're at 90% capacity. We can assume this won't\n // infinite loop because even if `maxLruSize` were 0, eventually\n // `deleteFromLru` sets `head` to `null` when we run out entries.\n const ninetyPercentMax = maxLruSize * 0.9\n while (lruSize > ninetyPercentMax && head !== null) {\n const tail = head.prev\n // In practice, this is never null, but that isn't encoded in the type\n if (tail !== null) {\n // Delete the entry from the map. In turn, this will remove it from\n // the LRU.\n deleteMapEntry(tail)\n }\n }\n}\n\nconst requestCleanupCallback =\n typeof requestIdleCallback === 'function'\n ? requestIdleCallback\n : (cb: () => void) => setTimeout(cb, 0)\n"],"names":["deleteMapEntry","head","didScheduleCleanup","lruSize","maxLruSize","lruPut","node","prev","next","size","ensureCleanupIsScheduled","tail","updateLruSize","newNodeSize","prevNodeSize","deleteFromLru","deleted","requestCleanupCallback","cleanup","ninetyPercentMax","requestIdleCallback","cb","setTimeout"],"mappings":"AAAA,SAASA,cAAc,QAAQ,cAAa;AAG5C,8EAA8E;AAC9E,2DAA2D;AAE3D,IAAIC,OAA+B;AACnC,IAAIC,qBAA8B;AAClC,IAAIC,UAAkB;AAEtB,+EAA+E;AAC/E,0EAA0E;AAC1E,4CAA4C;AAC5C,MAAMC,aAAa,KAAK,OAA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