stacks-cache

Implement memory and Redis caching with TTL management in Stacks apps.

622|17|Updated Apr 26, 2022
One-click install
npx skills add https://github.com/stacksjs/stacks --skill stacks-cache
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: stacks-cache
Source: https://github.com/stacksjs/stacks/tree/main/.claude/skills/stacks-cache
Command: npx skills add https://github.com/stacksjs/stacks --skill stacks-cache

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Caching reduces database load and speeds up response times by storing frequently accessed data in memory or Redis, eliminating repeated expensive computations.

Core Features & Use Cases

  • In-memory and Redis cache support with TTL and automatic eviction.
  • Cache-aside pattern (getOrSet) for on-demand computation and caching.
  • Factory helpers and configuration integration (config/cache.ts) for consistent defaults.

Quick Start

Create a memory cache via createMemoryCache and start caching results with cache.get/set in your application.

Frequently Asked Questions about stacks-cache

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

FAQPage Schema
How do I implement caching in a Stacks application?

Implement caching in your Stacks app by using the cache API for get, set, and getOrSet operations. Configure default behaviors in config/cache.ts and utilize createMemoryCache for fast in-memory storage to reduce database load.

What is the cache-aside pattern and how does getOrSet work?

The cache-aside pattern using getOrSet checks the cache first, computes the value on miss, stores it automatically, and returns the result. This on-demand caching approach eliminates repeated expensive computations and reduces database load.

Can I use Redis for caching in Stacks?

Yes, Stacks caching supports both Redis and in-memory storage. Both options provide TTL management and automatic eviction, allowing you to scale your application caching strategy according to your infrastructure and performance requirements.

How do I manage cache expiration and TTL in Stacks?

Manage cache expiration in Stacks using the ttl method within the cache API. Configure default TTL values in config/cache.ts to ensure safe defaults and predictable automatic eviction behavior across both memory and Redis caches.

Does Stacks caching support retrieving multiple cache keys at once?

Yes, Stacks caching supports mget to retrieve multiple cache keys simultaneously. This batch fetching capability reduces network round trips when accessing grouped data sets, improving overall application response times.

What is the best way to clear cached data in a Stacks app?

The best way to clear cached data in a Stacks app is using the clear method from the cache API. This empties stored values entirely, allowing you to reset stale data and enforce fresh computations across memory or Redis caches.