| 186 | } |
| 187 | |
| 188 | class ScopedCacheImpl<in out Key, in out Environment, in out Error, in out Value> |
| 189 | implements ScopedCache.ScopedCache<Key, Value, Error> |
| 190 | { |
| 191 | readonly [ScopedCacheTypeId] = scopedCacheVariance |
| 192 | readonly cacheState: CacheState<Key, Value, Error> |
| 193 | constructor( |
| 194 | readonly capacity: number, |
| 195 | readonly scopedLookup: ScopedCache.Lookup<Key, Value, Error, Environment>, |
| 196 | readonly clock: Clock.Clock, |
| 197 | readonly timeToLive: (exit: Exit.Exit<Value, Error>) => Duration.Duration, |
| 198 | readonly context: Context.Context<Environment> |
| 199 | ) { |
| 200 | this.cacheState = initialCacheState() |
| 201 | } |
| 202 | |
| 203 | pipe() { |
| 204 | return pipeArguments(this, arguments) |
| 205 | } |
| 206 | |
| 207 | get cacheStats(): Effect.Effect<Cache.CacheStats> { |
| 208 | return core.sync(() => |
| 209 | cache_.makeCacheStats({ |
| 210 | hits: this.cacheState.hits, |
| 211 | misses: this.cacheState.misses, |
| 212 | size: MutableHashMap.size(this.cacheState.map) |
| 213 | }) |
| 214 | ) |
| 215 | } |
| 216 | |
| 217 | getOption(key: Key): Effect.Effect<Option.Option<Value>, Error, Scope.Scope> { |
| 218 | return core.suspend(() => |
| 219 | Option.match(MutableHashMap.get(this.cacheState.map, key), { |
| 220 | onNone: () => effect.succeedNone, |
| 221 | onSome: (value) => core.flatten(this.resolveMapValue(value)) |
| 222 | }) |
| 223 | ) |
| 224 | } |
| 225 | |
| 226 | getOptionComplete(key: Key): Effect.Effect<Option.Option<Value>, never, Scope.Scope> { |
| 227 | return core.suspend(() => |
| 228 | Option.match(MutableHashMap.get(this.cacheState.map, key), { |
| 229 | onNone: () => effect.succeedNone, |
| 230 | onSome: (value) => |
| 231 | core.flatten(this.resolveMapValue(value, true)) as Effect.Effect<Option.Option<Value>, never, Scope.Scope> |
| 232 | }) |
| 233 | ) |
| 234 | } |
| 235 | |
| 236 | contains(key: Key): Effect.Effect<boolean> { |
| 237 | return core.sync(() => MutableHashMap.has(this.cacheState.map, key)) |
| 238 | } |
| 239 | |
| 240 | entryStats(key: Key): Effect.Effect<Option.Option<Cache.EntryStats>> { |
| 241 | return core.sync(() => { |
| 242 | const value = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, key)) |
| 243 | if (value === undefined) { |
| 244 | return Option.none() |
| 245 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…