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

Function keys

packages/effect/src/ScopedCache.ts:739–755  ·  view source on GitHub ↗
(self: ScopedCache<Key, A, E, R>)

Source from the content-addressed store, hash-verified

737 * @since 4.0.0
738 */
739export const keys = <Key, A, E, R>(self: ScopedCache<Key, A, E, R>): Effect.Effect<Array<Key>> =>
740 core.withFiber((fiber) => {
741 if (self.state._tag === "Closed") return effect.succeed([])
742 const state = self.state
743 const now = fiber.getRef(effect.ClockRef).currentTimeMillisUnsafe()
744 const fibers = Arr.empty<Fiber.Fiber<unknown, unknown>>()
745 const keys: Array<Key> = []
746 for (const [key, entry] of state.map) {
747 if (entry.expiresAt === undefined || entry.expiresAt > now) {
748 keys.push(key)
749 } else {
750 MutableHashMap.remove(state.map, key)
751 fibers.push(effect.forkUnsafe(fiber, Scope.close(entry.scope, effect.exitVoid), true, true))
752 }
753 }
754 return fibers.length === 0 ? effect.succeed(keys) : effect.as(effect.fiberAwaitAll(fibers), keys)
755 })
756
757/**
758 * Retrieves all successfully cached values from the cache, excluding failed

Callers

nothing calls this directly

Calls 6

getRefMethod · 0.80
pushMethod · 0.80
closeMethod · 0.65
succeedMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected