effect-cache

Implements keyed in-memory caching for Effect lookups with TTL, LRU eviction, and scoped resources.

3|Updated Apr 1, 2026
One-click install
npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-cache-mpsuesser
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-cache
Source: https://github.com/mpsuesser/opencode-effect-enforcer/tree/main/skills/effect-cache
Command: npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-cache-mpsuesser

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires effect.

What problem does it solve? Repeated effectful lookups against APIs or databases waste latency and resources, and naive memoization mishandles failures, concurrent fetches, and resource cleanup. This Skill teaches correct use of Effect's Cache and ScopedCache so lookups are deduplicated, failures get bounded lifetimes, and cached resources are released deterministically. ## Core Features & Use Cases - Keyed caching with Cache: Create caches with capacity limits, fixed or exit-aware TTLs, LRU eviction, deduplicated concurrent lookups, and refresh/invalidation operations. - Resource-owning entries with ScopedCache: Cache values like connections that own a per-entry Scope, with finalizers running on eviction, expiry, invalidation, or cache close. - Single-value memoization: Use Effect.cached, cachedWithTTL, and cachedInvalidateWithTTL when no key is needed. - Use Case: Build a cached user repository service as a Layer where reads hit a 10,000-entry cache with a 5-minute success TTL, failures expire in seconds, and writes update the cache through Cache.set. ## Quick Start Ask the agent to add TTL-based caching with Cache.makeWith to an Effect service that fetches users by id, including a short TTL for failures.

Frequently Asked Questions about effect-cache

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I cache effectful lookups by key in Effect TypeScript?

Use Cache.make with a lookup function, capacity, and optional timeToLive, then call Cache.get(cache, key). Concurrent gets of the same missing key share one lookup, and both successes and failures are cached until expiry or invalidation.

What is the difference between Cache and ScopedCache in Effect?

Cache stores plain values, while ScopedCache gives each entry its own Scope so lookups can acquire resources like connections that are released on eviction, expiry, invalidation, or cache close. ScopedCache construction itself requires a Scope.

Why does a cached Effect lookup keep failing after one transient error?

Failures are cached with the default infinite TTL, so one error fails that key forever. Use Cache.makeWith with an exit-aware TTL, returning a short duration or Duration.zero for non-success exits, which also covers interrupted lookups.

How do I test cache TTL expiration in Effect?

TTL is computed against the fiber's Clock, so TestClock works directly. Adjust time with TestClock.adjust and assert with Cache.has; expiry is lazy, meaning entries are removed when next touched by an operation.

When should I use RcMap or Pool instead of Cache?

Use RcMap or LayerMap when a keyed resource must be retained until each caller's scope releases it, and effect/Pool for a fixed set of interchangeable resources checked out per use. Cache and ScopedCache fit keyed value memoization with TTL and LRU eviction.