epic-caching

Implement layered caching with cachified, SQLite, and LRU caches in the Epic Stack.

5.5k|464|Updated May 4, 2023
One-click install
npx skills add https://github.com/epicweb-dev/epic-stack --skill epic-caching
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: epic-caching
Source: https://github.com/epicweb-dev/epic-stack/tree/main/docs/skills/epic-caching
Command: npx skills add https://github.com/epicweb-dev/epic-stack --skill epic-caching

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Caching is a core performance technique, but without a structured approach it can introduce complexity, stale data, and unpredictable behavior. This Skill guides teams on implementing robust, layered caching across the Epic Stack, balancing speed, correctness, and maintainability.

Core Features & Use Cases

  • Caching philosophy: Clear guidelines for when to cache, which data to cache, how to invalidate, and how to reason about performance benefits.
  • Two cache backends: Persistent SQLite cache (with LiteFS replication) and a short-lived in-memory LRU cache for deduplication and fast access.
  • Use cases: Caching expensive Prisma queries, external API responses, and derived data with support for stale-while-revalidate and server timing integration.
  • Patterns: TTL, SWR, cache invalidation after mutations, and structured cache keys.

Quick Start

Install the caching utilities in your Epic Stack project, choose an appropriate cache backend, and wrap expensive data-fetching calls with cachified. Define a cache key, configure TTL and optional stale-while-revalidate, and wire server timing to monitor cache performance.

Frequently Asked Questions about epic-caching

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

FAQPage Schema
How do I implement stale-while-revalidate caching for Prisma queries in an Epic Stack app?

Stale-while-revalidate caching for Prisma queries is implemented using the cachified library. You wrap expensive data-fetching calls with cachified, define a structured cache key, and configure SWR behavior alongside a TTL to serve fast results while refreshing in the background.

What is the best way to cache external API responses with SQLite and LRU in the Epic Stack?

Caching external API responses requires a two-backend approach using a persistent SQLite cache and a short-lived in-memory LRU cache. SQLite handles durable storage with LiteFS replication, while LRU provides fast access and request deduplication.

How does cachified handle cache invalidation after database mutations?

Cache invalidation after mutations is handled by cachified through structured cache keys. The Skill provides guidelines on when to invalidate specific cached data, ensuring that database updates correctly clear stale entries and maintain data consistency.

Can I use Zod validation to verify cached data types in an Epic Stack application?

Yes, Zod validation is supported to verify cached data types. Cachified integrates with Zod to ensure that cached API responses and derived data conform to expected schemas upon retrieval, preventing type-related runtime errors.

How do I monitor caching performance using server timing in the Epic Stack?

Caching performance is monitored by wiring server timing integration into your cachified calls. This allows you to measure the execution time of cache hits and misses directly within the Epic Stack server response headers for safe, measured performance improvements.

Does the Epic Stack support multi-region cache replication with LiteFS?

Yes, multi-region cache replication is supported using LiteFS with the SQLite cache backend. This setup replicates the persistent cache across multiple regions, ensuring fast and reliable data access for distributed deployments.

Related Skills