Hyperlinkv0.8.0-beta.28

ScopedCache

ScopedCache.invalidateconsteffect/ScopedCache.ts:533
<Key, A>(key: Key): <E, R>(
  self: ScopedCache<Key, A, E, R>
) => Effect.Effect<void>
<Key, A, E, R>(
  self: ScopedCache<Key, A, E, R>,
  key: Key
): Effect.Effect<void>

Removes the entry associated with a key and closes its entry scope.

When to use

Use to remove a single key from a scoped cache and release any resources owned by that entry before a later lookup computes it again.

Details

If the key is absent, this is a no-op.

Gotchas

If the cache is closed, the effect is interrupted.

export const invalidate: {
  <Key, A>(key: Key): <E, R>(self: ScopedCache<Key, A, E, R>) => Effect.Effect<void>
  <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key): Effect.Effect<void>
} = dual(2, <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key): Effect.Effect<void> =>
  effect.uninterruptible(
    effect.suspend(() => {
      if (self.state._tag === "Closed") {
        return effect.interrupt
      }
      const oentry = MutableHashMap.get(self.state.map, key)
      if (Option.isNone(oentry)) {
        return effect.void
      }
      MutableHashMap.remove(self.state.map, key)
      return Scope.close(oentry.value.scope, effect.exitVoid)
    })
  ))