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

Function getCachedValue

packages/effect/src/internal/effect/circular.ts:277–306  ·  view source on GitHub ↗
(
  self: Effect.Effect<A, E, R>,
  timeToLive: Duration.DurationInput,
  cache: Synchronized.SynchronizedRef<Option.Option<readonly [number, Deferred.Deferred<A, E>]>>
)

Source from the content-addressed store, hash-verified

275
276/** @internal */
277const getCachedValue = <A, E, R>(
278 self: Effect.Effect<A, E, R>,
279 timeToLive: Duration.DurationInput,
280 cache: Synchronized.SynchronizedRef<Option.Option<readonly [number, Deferred.Deferred<A, E>]>>
281): Effect.Effect<A, E, R> =>
282 pipe(
283 effect.clockWith((clock) => clock.currentTimeMillis),
284 core.flatMap((time) =>
285 updateSomeAndGetEffectSynchronized(cache, (option) => {
286 switch (option._tag) {
287 case "None": {
288 return Option.some(computeCachedValue(self, timeToLive, time))
289 }
290 case "Some": {
291 const [end] = option.value
292 return end - time <= 0
293 ? Option.some(computeCachedValue(self, timeToLive, time))
294 : Option.none()
295 }
296 }
297 })
298 ),
299 core.flatMap((option) =>
300 Option.isNone(option) ?
301 core.dieMessage(
302 "BUG: Effect.cachedInvalidate - please report an issue at https://github.com/Effect-TS/effect/issues"
303 ) :
304 core.deferredAwait(option.value[1])
305 )
306 )
307
308/** @internal */
309const invalidateCache = <A, E>(

Callers 1

circular.tsFile · 0.85

Calls 3

computeCachedValueFunction · 0.85
pipeFunction · 0.70
dieMessageMethod · 0.65

Tested by

no test coverage detected