(scope: ServerScope)
| 121 | } |
| 122 | |
| 123 | export 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 | } |
no test coverage detected