MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / createViewCache

Function createViewCache

packages/frontend/src/controller.tsx:72–105  ·  view source on GitHub ↗

* Views when disposed can cache their state to be restored when opened again. * The short cache is cleared after 3 seconds of inactivity. * The long cache is cleared when the view is opened again.

()

Source from the content-addressed store, hash-verified

70 * The long cache is cleared when the view is opened again.
71 */
72function createViewCache() {
73 type CacheDataMap = {
74 [debug.DevtoolsMainView.Structure]: structure.Cache
75 }
76 let shortCache: null | any = null
77 let nextShortCache: typeof shortCache = null
78 const longCache = new Map<keyof CacheDataMap, any>()
79
80 const clearShortCache = debounce(() => {
81 shortCache = null
82 nextShortCache = null
83 }, 3 * SECOND)
84
85 function setCacheGetter<T extends debug.DevtoolsMainView>(view: T, getter: () => CacheDataMap[T]) {
86 s.onCleanup(() => {
87 const data = getter()
88 nextShortCache = {view: view as any, data: data.short}
89 longCache.set(view, data.long)
90 clearShortCache()
91 })
92 }
93 function getCache<T extends debug.DevtoolsMainView>(
94 view: T,
95 ): {[K in 'short' | 'long']: CacheDataMap[T][K] | null} {
96 const short = shortCache && shortCache.view === view ? shortCache.data : null
97 shortCache = nextShortCache
98 nextShortCache = null
99 const long = longCache.get(view)
100 longCache.delete(view)
101 return {short, long}
102 }
103
104 return {set: setCacheGetter, get: getCache}
105}
106
107function createAppCtx(props: DevtoolsOptions) {
108

Callers 1

createAppCtxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…