sdxc-cache

Implements a Result-returning cache contract with MemoryCache and Cloudflare KV adapters.

5|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/sergiodxa/monorepo --skill sdxc-cache-sergiodxa
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sdxc-cache
Source: https://github.com/sergiodxa/monorepo/tree/main/.agents/skills/sdxc-cache
Command: npx skills add https://github.com/sergiodxa/monorepo --skill sdxc-cache-sergiodxa

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @sdxc/result, @sdxc/duration.

What problem does it solve? Repeated database reads and upstream API calls waste latency and quota, and ad-hoc caching code tends to throw exceptions, hide TTL behavior, and behave differently in tests than in production. This Skill documents a cache contract where every call answers with a Result instead of throwing, with adapters that behave identically across environments. ## Core Features & Use Cases - Unified Cache Contract: One interface covers read, write, fetch, and delete, each returning a Result carrying a typed CacheError instead of throwing. - Swappable Adapters: MemoryCache runs in-process for tests while WorkerKVCache binds to a Cloudflare KV namespace in production, both passing the same Vitest conformance suite. - TTL and Failure Semantics: TTLs accept duration strings like "5 minutes", and CacheError codes (unavailable, invalid_value, load_failed) let callers distinguish a miss from an unreachable store. - Use Case: Memoize a per-request database query behind cache.fetch(post:${id}, loader, { ttl: "5 minutes" }) in a Cloudflare Worker, then swap in MemoryCache with a fake clock to test expiry without a KV namespace. ## Quick Start Add @sdxc/cache as a workspace dependency and ask the agent to wrap a repeated database query in cache.fetch with a five-minute TTL using WorkerKVCache.

Frequently Asked Questions about sdxc-cache

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

FAQPage Schema
How do I cache a database query in a Cloudflare Worker?▼

Create a WorkerKVCache with your KV binding and call cache.fetch with a key, a loader function, and a TTL like "5 minutes". The fetch method returns the cached value or computes, stores, and returns the loaded value, always as a Result.

How do I test code that uses a cache without a KV namespace?▼

Use MemoryCache from @sdxc/cache/memory, which stores entries in an in-process map. It serializes on write and parses on read like the KV adapter, and accepts a now function so you can expire entries without waiting.

Does WorkerKVCache support TTLs under 60 seconds?▼

No. Cloudflare KV refuses TTLs under 60 seconds, so a shorter TTL leaves the entry unwritten and the call reports an unavailable error. Use TTLs of 60 seconds or longer with WorkerKVCache.

Why does a cached Date come back as a string?▼

The cache stores JSON-serialized values, so what reads back is what the store serialized, not the original object. The fetch method types the result as JSONSerialized<T> to reflect this.

When should I write a custom cache adapter?▼

Write an adapter when you need a backing store other than memory or Workers KV, such as Redis, D1, or the Cache API. Run the Vitest conformance suite from @sdxc/cache/conformance to prove the new adapter behaves like a cache.