MCPcopy Create free account
hub / github.com/epicweb-dev/epic-stack / cachifiedTimingReporter

Function cachifiedTimingReporter

app/utils/timing.server.ts:93–121  ·  view source on GitHub ↗
(
	timings?: Timings,
)

Source from the content-addressed store, hash-verified

91}
92
93export function cachifiedTimingReporter<Value>(
94 timings?: Timings,
95): undefined | CreateReporter<Value> {
96 if (!timings) return
97
98 return ({ key }) => {
99 const cacheRetrievalTimer = createTimer(
100 `cache:${key}`,
101 `${key} cache retrieval`,
102 )
103 let getFreshValueTimer: ReturnType<typeof createTimer> | undefined
104 return (event) => {
105 switch (event.name) {
106 case 'getFreshValueStart':
107 getFreshValueTimer = createTimer(
108 `getFreshValue:${key}`,
109 `request forced to wait for a fresh ${key} value`,
110 )
111 break
112 case 'getFreshValueSuccess':
113 getFreshValueTimer?.end(timings)
114 break
115 case 'done':
116 cacheRetrievalTimer.end(timings)
117 break
118 }
119 }
120 }
121}

Callers 1

cachifiedFunction · 0.90

Calls 1

createTimerFunction · 0.85

Tested by

no test coverage detected