Agent skill
caching-optimizer
Optimize caching strategies for performance. Use when analyzing cache effectiveness, implementing multi-layer caching, optimizing Redis/memory caches, or troubleshooting slow response times.
Install this agent skill to your Project
npx add-skill https://github.com/j0KZ/mcp-agents/tree/main/starter-kit/template/.claude/skills/caching-optimizer
SKILL.md
Caching Optimizer
Intelligent caching strategy optimization for applications and APIs
Quick Commands
# Analyze cache effectiveness
npx @j0kz/caching-optimizer analyze
# Generate caching strategy
npx @j0kz/caching-optimizer suggest --profile=api
# Clear and warm cache
npm run cache:clear && npm run cache:warm
# Monitor cache metrics
npx @j0kz/caching-optimizer monitor
Core Functionality
Key Features
- Cache Analysis: Hit/miss ratios and effectiveness
- Strategy Optimization: LRU, LFU, TTL recommendations
- Multi-Layer Caching: Memory, Redis, CDN coordination
- Cache Warming: Preload frequently accessed data
- Invalidation Strategies: Smart cache busting
Detailed Information
For comprehensive details, see:
cat .claude/skills/caching-optimizer/references/caching-patterns.md
cat .claude/skills/caching-optimizer/references/redis-optimization.md
cat .claude/skills/caching-optimizer/references/cdn-strategies.md
Usage Examples
Example 1: Implement Multi-Layer Cache
import { CachingOptimizer } from '@j0kz/caching-optimizer';
const optimizer = new CachingOptimizer({
layers: [
{ type: 'memory', size: '100MB', ttl: 300 },
{ type: 'redis', size: '1GB', ttl: 3600 },
{ type: 'cdn', ttl: 86400 }
]
});
// Automatic layer selection
const data = await optimizer.get('user:123', async () => {
return await fetchUserFromDB(123);
});
Example 2: Cache Effectiveness Analysis
const metrics = await optimizer.analyze({
period: '24h',
breakdown: true
});
console.log(`Hit Rate: ${metrics.hitRate}%`);
console.log(`Miss Rate: ${metrics.missRate}%`);
console.log(`Eviction Rate: ${metrics.evictionRate}%`);
// Get recommendations
const suggestions = optimizer.suggest(metrics);
suggestions.forEach(s => console.log(s));
Caching Strategies
Common Patterns
-
Cache-Aside (Lazy Loading)
javascriptconst data = cache.get(key) || await loadAndCache(key); -
Write-Through
javascriptawait Promise.all([ cache.set(key, data), database.save(key, data) ]); -
Write-Behind (Write-Back)
javascriptcache.set(key, data); queue.push({ action: 'save', key, data });
Cache Keys Strategy
// Hierarchical keys for batch invalidation
const keyPatterns = {
user: 'user:{id}',
userPosts: 'user:{userId}:posts',
post: 'post:{id}',
postComments: 'post:{postId}:comments:{page}'
};
Configuration
{
"caching-optimizer": {
"default": {
"strategy": "lru",
"maxSize": "512MB",
"ttl": 3600,
"compression": true
},
"layers": {
"memory": {
"enabled": true,
"maxSize": "128MB"
},
"redis": {
"enabled": true,
"cluster": false,
"db": 0
},
"cdn": {
"enabled": true,
"provider": "cloudflare"
}
},
"monitoring": {
"metrics": ["hitRate", "missRate", "latency"],
"alertThreshold": {
"hitRate": 0.8,
"latency": 100
}
}
}
}
Cache Invalidation
// Tag-based invalidation
await optimizer.tag(['user:123', 'posts']).set(key, data);
await optimizer.invalidateTag('user:123');
// Pattern-based invalidation
await optimizer.invalidatePattern('user:123:*');
// Time-based invalidation
await optimizer.set(key, data, { ttl: 3600, slide: true });
Notes
- Supports Redis, Memcached, and in-memory caching
- Automatic cache stampede prevention
- Compression for large values
- Distributed caching support for microservices
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
debug-detective
Systematic debugging approach for ANY codebase, ANY language, ANY bug type
tool-discovery
Guide for discovering and using @j0kz MCP tools efficiently through search, filtering, and progressive exploration. Use when exploring available capabilities, finding the right tool for a task, or ...
project-standardization
Guides correct usage of @j0kz/mcp-agents standardization and automation scripts including version.json single source of truth, test count automation, URL casing rules, and critical workflow pattern...
api-integration
Master third-party API integration in ANY language with best practices and patterns
documentation-generation
Documentation generation and maintenance patterns including README structure, CHANGELOG management, API documentation, wiki synchronization, and badge updates. Use when creating package docs, updat...
competitive-ads-extractor
Extracts and analyzes competitor ads from ad libraries (Facebook, LinkedIn, TikTok, Google). Use when researching competitor messaging, creative patterns, campaign strategies, or ad inspiration. Ch...
Didn't find tool you were looking for?