MCPcopy Create free account
hub / github.com/modelcontextprotocol/ext-apps / setCacheEntry

Function setCacheEntry

examples/pdf-server/server.ts:744–767  ·  view source on GitHub ↗

Add data to cache with both inactivity and max lifetime timers

(url: string, data: Uint8Array)

Source from the content-addressed store, hash-verified

742
743 /** Add data to cache with both inactivity and max lifetime timers */
744 function setCacheEntry(url: string, data: Uint8Array): void {
745 // Clear any existing entry first
746 deleteCacheEntry(url);
747
748 // Evict least-recently-used entries until under the byte cap.
749 for (const oldest of cache.keys()) {
750 if (totalBytes + data.length <= maxTotalBytes) break;
751 deleteCacheEntry(oldest);
752 }
753
754 const entry: CacheEntry = {
755 data,
756 createdAt: Date.now(),
757 inactivityTimer: setTimeout(() => {
758 deleteCacheEntry(url);
759 }, CACHE_INACTIVITY_TIMEOUT_MS),
760 maxLifetimeTimer: setTimeout(() => {
761 deleteCacheEntry(url);
762 }, CACHE_MAX_LIFETIME_MS),
763 };
764
765 cache.set(url, entry);
766 totalBytes += data.length;
767 }
768
769 /** Slice a cached or freshly-fetched full body to the requested range. */
770 function sliceToChunk(

Callers 1

readPdfRangeFunction · 0.85

Calls 1

deleteCacheEntryFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…