MCPcopy Index your code
hub / github.com/Effect-TS/effect / refresh

Method refresh

packages/effect/src/internal/scopedCache.ts:338–389  ·  view source on GitHub ↗
(key: Key)

Source from the content-addressed store, hash-verified

336 }
337
338 refresh(key: Key): Effect.Effect<void, Error> {
339 return pipe(
340 this.lookupValueOf(key),
341 effect.memoize,
342 core.flatMap((scoped) => {
343 let value = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, key))
344 let newKey: cache_.MapKey<Key> | undefined = undefined
345 if (value === undefined) {
346 newKey = cache_.makeMapKey(key)
347 if (MutableHashMap.has(this.cacheState.map, key)) {
348 value = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, key))
349 } else {
350 MutableHashMap.set(this.cacheState.map, key, pending(newKey, scoped))
351 }
352 }
353 let finalScoped: Effect.Effect<Effect.Effect<Value, Error, Scope.Scope>>
354 if (value === undefined) {
355 finalScoped = core.zipRight(
356 this.ensureMapSizeNotExceeded(newKey!),
357 scoped
358 )
359 } else {
360 switch (value._tag) {
361 case "Complete": {
362 if (this.hasExpired(value.timeToLive)) {
363 finalScoped = core.succeed(this.get(key))
364 } else {
365 const current = Option.getOrUndefined(MutableHashMap.get(this.cacheState.map, key))
366 if (Equal.equals(current, value)) {
367 const mapValue = refreshing(scoped, value)
368 MutableHashMap.set(this.cacheState.map, key, mapValue)
369 finalScoped = scoped
370 } else {
371 finalScoped = core.succeed(this.get(key))
372 }
373 }
374 break
375 }
376 case "Pending": {
377 finalScoped = value.scoped
378 break
379 }
380 case "Refreshing": {
381 finalScoped = value.scoped
382 break
383 }
384 }
385 }
386 return core.flatMap(finalScoped, (s) => fiberRuntime.scopedEffect(core.asVoid(s)))
387 })
388 )
389 }
390
391 get size(): Effect.Effect<number> {
392 return core.sync(() => MutableHashMap.size(this.cacheState.map))

Callers

nothing calls this directly

Calls 9

lookupValueOfMethod · 0.95
hasExpiredMethod · 0.95
getMethod · 0.95
pipeFunction · 0.70
pendingFunction · 0.70
refreshingFunction · 0.70
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected