(key: Key)
| 258 | } |
| 259 | |
| 260 | get(key: Key): Effect.Effect<Value, Error, Scope.Scope> { |
| 261 | return pipe( |
| 262 | this.lookupValueOf(key), |
| 263 | effect.memoize, |
| 264 | core.flatMap((lookupValue) => |
| 265 | core.suspend(() => { |
| 266 | let k: cache_.MapKey<Key> | undefined = undefined |
| 267 | let value = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, key)) |
| 268 | if (value === undefined) { |
| 269 | k = cache_.makeMapKey(key) |
| 270 | if (MutableHashMap.has(this.cacheState.map, key)) { |
| 271 | value = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, key)) |
| 272 | } else { |
| 273 | MutableHashMap.set(this.cacheState.map, key, pending(k, lookupValue)) |
| 274 | } |
| 275 | } |
| 276 | if (value === undefined) { |
| 277 | this.trackMiss() |
| 278 | return core.zipRight( |
| 279 | this.ensureMapSizeNotExceeded(k!), |
| 280 | lookupValue |
| 281 | ) |
| 282 | } |
| 283 | |
| 284 | return core.map( |
| 285 | this.resolveMapValue(value), |
| 286 | core.flatMap(Option.match({ |
| 287 | onNone: () => { |
| 288 | const val = value as Complete<Key, Value, Error> |
| 289 | const current = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, key)) |
| 290 | if (Equal.equals(current, value)) { |
| 291 | MutableHashMap.remove(this.cacheState.map, key) |
| 292 | } |
| 293 | return pipe( |
| 294 | this.ensureMapSizeNotExceeded(val.key), |
| 295 | core.zipRight(releaseOwner(val)), |
| 296 | core.zipRight(this.get(key)) |
| 297 | ) |
| 298 | }, |
| 299 | onSome: core.succeed |
| 300 | })) |
| 301 | ) |
| 302 | }) |
| 303 | ), |
| 304 | core.flatten |
| 305 | ) |
| 306 | } |
| 307 | |
| 308 | invalidate(key: Key): Effect.Effect<void> { |
| 309 | return core.suspend(() => { |
no test coverage detected