Performance
Caching
Add caching to any route with one line — automatic TTL, dynamic keys, and smart invalidation, with no manual key management.
Overview
Without caching, every request hits your database or expensive operations. With caching, repeated responses are served instantly — and MoroJS handles the keys, expiration, and invalidation for you.
Add caching with one line
typescript
Without caching
- Every request hits the database
- Slow response times
- High server load
- Manual cache management
With MoroJS
- Instant responses from cache
- Reduced database load
- Automatic TTL management
- One-line setup
Fast
Instant responses from cache. No database queries for cached data.
Automatic
TTL-based expiration. No manual cache management needed.
Simple
One line of code. Dynamic keys. Smart invalidation.
How It Works
MoroJS caching automatically stores responses based on cache keys and TTL (time-to-live) values. When a request comes in, it checks the cache first. If found, it returns immediately. If not, it executes the handler and stores the result.
Route-Level Caching
Basic Route Caching
typescript
Different TTLs for Different Data
typescript
Advanced Caching
For advanced use cases, you can integrate external caching solutions like Redis, implement tag-based invalidation, and manage cache manually.
Tag-Based Invalidation
typescript
Manual Cache Management
typescript