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

Function makeTestCache

packages/effect/test/Cache.test.ts:1487–1511  ·  view source on GitHub ↗
(capacity: number, ttl?: Duration.Input)

Source from the content-addressed store, hash-verified

1485})
1486
1487const makeTestCache = (capacity: number, ttl?: Duration.Input) =>
1488 Effect.gen(function*() {
1489 let lookupCount = 0
1490 const lookupResults = new Map<string, Effect.Effect<number, string>>()
1491
1492 const cache = yield* Cache.make<string, number, string>({
1493 capacity,
1494 lookup: (key) => {
1495 lookupCount++
1496 return lookupResults.get(key) ?? Effect.fail(`Key not found: ${key}`)
1497 },
1498 timeToLive: ttl
1499 })
1500
1501 return {
1502 cache,
1503 lookupCount: () => lookupCount,
1504 resetLookupCount: () => {
1505 lookupCount = 0
1506 },
1507 setLookupResult: (key: string, result: Effect.Effect<number, string>) => {
1508 lookupResults.set(key, result)
1509 }
1510 }
1511 })

Callers 1

Cache.test.tsFile · 0.85

Calls 4

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

Tested by

no test coverage detected