MCPcopy Create free account
hub / github.com/breck7/scroll / fetchWithCache

Function fetchWithCache

external/.scrollLibs.js:21650–21686  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

21648const urlCache = {}
21649const pendingRequests = {}
21650async function fetchWithCache(url) {
21651 const now = Date.now()
21652 const cached = urlCache[url]
21653 if (cached) return cached
21654 // If there's already a pending request for this URL, return that promise
21655 if (pendingRequests[url]) {
21656 return pendingRequests[url]
21657 }
21658 // Create new request and store in pending
21659 const requestPromise = (async () => {
21660 try {
21661 const response = await fetch(url)
21662 if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`)
21663 const content = await response.text()
21664 const result = {
21665 content,
21666 timestamp: now,
21667 exists: true
21668 }
21669 urlCache[url] = result
21670 return result
21671 } catch (error) {
21672 console.error(`Error fetching ${url}:`, error)
21673 const result = {
21674 content: "",
21675 timestamp: now,
21676 exists: false
21677 }
21678 urlCache[url] = result
21679 return result
21680 } finally {
21681 delete pendingRequests[url]
21682 }
21683 })()
21684 pendingRequests[url] = requestPromise
21685 return requestPromise
21686}
21687class DiskWriter {
21688 constructor() {
21689 this.fileCache = {}

Callers 4

_readMethod · 0.85
existsMethod · 0.85
readMethod · 0.85
existsMethod · 0.85

Calls 1

textMethod · 0.80

Tested by

no test coverage detected