(capacity: number, ttl?: Duration.Input)
| 1485 | }) |
| 1486 | |
| 1487 | const 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 | }) |
no test coverage detected