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

Function getImpl

packages/effect/src/ScopedCache.ts:446–470  ·  view source on GitHub ↗
(
  self: ScopedCache<Key, A, E, R>,
  key: Key,
  fiber: Fiber.Fiber<any, any>,
  isRead = true
)

Source from the content-addressed store, hash-verified

444)
445
446const getImpl = <Key, A, E, R>(
447 self: ScopedCache<Key, A, E, R>,
448 key: Key,
449 fiber: Fiber.Fiber<any, any>,
450 isRead = true
451): Effect.Effect<Entry<A, E> | undefined> => {
452 if (self.state._tag === "Closed") {
453 return effect.interrupt
454 }
455 const state = self.state
456 const oentry = MutableHashMap.get(state.map, key)
457 if (Option.isNone(oentry)) {
458 return effect.undefined
459 } else if (hasExpired(oentry.value, fiber)) {
460 MutableHashMap.remove(state.map, key)
461 return effect.as(
462 closeEvicted(oentry.value),
463 undefined
464 )
465 } else if (isRead) {
466 MutableHashMap.remove(state.map, key)
467 MutableHashMap.set(state.map, key, oentry.value)
468 }
469 return effect.succeed(oentry.value)
470}
471
472/**
473 * Retrieves the value associated with the specified key from the cache, only if

Callers 1

ScopedCache.tsFile · 0.70

Calls 6

closeEvictedFunction · 0.85
hasExpiredFunction · 0.70
getMethod · 0.65
removeMethod · 0.65
setMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected