(capacity: number, ttl?: Duration.Input)
| 2275 | |
| 2276 | // Helper functions for testing |
| 2277 | const 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 |
| 2304 | interface CleanupTracker { |
no test coverage detected