MCPcopy Index your code
hub / github.com/anomalyco/opencode / createFileViewCache

Function createFileViewCache

packages/app/src/context/file/view-cache.ts:123–147  ·  view source on GitHub ↗
(scope: ServerScope)

Source from the content-addressed store, hash-verified

121}
122
123export function createFileViewCache(scope: ServerScope) {
124 const cache = createScopedCache(
125 (key) => {
126 const split = key.lastIndexOf("\n")
127 const dir = split >= 0 ? key.slice(0, split) : key
128 const id = split >= 0 ? key.slice(split + 1) : WORKSPACE_KEY
129 return createRoot((dispose) => ({
130 value: createViewSession(scope, dir, id === WORKSPACE_KEY ? undefined : id),
131 dispose,
132 }))
133 },
134 {
135 maxEntries: MAX_FILE_VIEW_SESSIONS,
136 dispose: (entry) => entry.dispose(),
137 },
138 )
139
140 return {
141 load: (dir: string, id: string | undefined) => {
142 const key = `${dir}\n${id ?? WORKSPACE_KEY}`
143 return cache.get(key).value
144 },
145 clear: () => cache.clear(),
146 }
147}

Callers 1

file.tsxFile · 0.90

Calls 5

createScopedCacheFunction · 0.90
createViewSessionFunction · 0.85
getMethod · 0.65
disposeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected