serverpod-caching

Cache frequently accessed data in Serverpod sessions using session.caches APIs.

3.2k|369|Updated May 22, 2021
One-click install
npx skills add https://github.com/serverpod/serverpod --skill serverpod-caching
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: serverpod-caching
Source: https://github.com/serverpod/serverpod/tree/main/packages/serverpod/skills/serverpod-caching
Command: npx skills add https://github.com/serverpod/serverpod --skill serverpod-caching

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Server-side performance suffers when repeated database reads and expensive queries happen every time a request comes in, especially for data that does not change often.

Core Features & Use Cases

  • Local and Redis caches: Store and retrieve cached values via session.caches to reduce repeated work within and across server instances.
  • Typed get/put and primitive support: Cache serializable models or supported primitives with strong typing for reads.
  • CacheMissHandler for automatic population: Compute the value only on cache misses and store it with a configured lifetime.
  • Cache groups for invalidation: Use groups to help coordinate cache invalidation patterns for related entries.

Quick Start

Use the serverpod-caching skill to cache frequently requested data in session.caches.local or session.caches.global with a safe lifetime and a stable key like EntityName-id.

Frequently Asked Questions about serverpod-caching

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

FAQPage Schema
How do I reduce redundant database queries in Serverpod?

Reduce redundant Serverpod database queries by storing frequently accessed data in session.caches. Use local in-memory storage for session-level caching or Redis-backed global caching to avoid repeated reads.

What is a CacheMissHandler and how does it work for caching?

A CacheMissHandler automatically computes and stores values only when a cache lookup fails. Configured with an explicit lifetime, it populates the cache on demand without manual get-put logic.

How do I invalidate related cache entries in Serverpod?

Invalidate related Serverpod cache entries by assigning them to cache groups. Grouping coordinated entries allows targeted invalidation patterns to clear stale data across related keys when underlying values change.

Can I cache custom data models or only primitives in Serverpod session caches?

You can cache both serializable custom models and supported primitives in Serverpod session caches. Typed get and put APIs ensure strongly typed reads for retrieving stored values.

What is the best way to structure cache keys for Serverpod request workflows?

Structure Serverpod cache keys using stable, deterministic formats like EntityName-id. Well-formed keys prevent collisions and ensure accurate data retrieval across request and real-time workflows.

When should I use local in-memory caching vs Redis global caching in Serverpod?

Use local in-memory caching for session-specific data within a single instance, and Redis global caching for shared data across multiple Serverpod instances. Both require explicit lifetime configuration to manage expiration.