MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeScopedTestCache

Function makeScopedTestCache

packages/effect/test/ScopedCache.test.ts:2277–2301  ·  view source on GitHub ↗
(capacity: number, ttl?: Duration.Input)

Source from the content-addressed store, hash-verified

2275
2276// Helper functions for testing
2277const makeScopedTestCache = (capacity: number, ttl?: Duration.Input) =>
2278 Effect.gen(function*() {
2279 let lookupCount = 0
2280 const lookupResults = new Map<string, Effect.Effect<number, string>>()
2281
2282 const cache = yield* ScopedCache.make({
2283 capacity,
2284 lookup: (key: string) => {
2285 lookupCount++
2286 return lookupResults.get(key) ?? Effect.fail(`Key not found: ${key}`)
2287 },
2288 timeToLive: ttl
2289 })
2290
2291 return {
2292 cache,
2293 lookupCount: () => lookupCount,
2294 resetLookupCount: () => {
2295 lookupCount = 0
2296 },
2297 setLookupResult: (key: string, result: Effect.Effect<number, string>) => {
2298 lookupResults.set(key, result)
2299 }
2300 }
2301 })
2302
2303// Helper for tracking resource cleanup
2304interface CleanupTracker {

Callers 1

Calls 4

makeMethod · 0.65
getMethod · 0.65
setMethod · 0.65
failMethod · 0.45

Tested by

no test coverage detected