Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Implement multi-tier database caching with Redis, in-memory, and CDN layers...
shortcut
cach
Database Cache Layer
Implement production-grade multi-tier caching architecture for databases using Redis (distributed cache), in-memory caching (L1), and CDN (static assets) to reduce database load by 80-95%, improve query latency from 50ms to 1-5ms, and support horizontal scaling with cache-aside, write-through, and read-through patterns.
When to Use This Command
Use /caching when you need to:
Reduce database load by caching frequently accessed data (80% hit rate)
Improve query response times from 50-100ms to 1-5ms
Handle traffic spikes without database scaling (cache absorbs load)
Support read-heavy workloads with minimal database reads
Implement distributed caching across multiple application servers
Enable horizontal scaling with stateless application servers
DON'T use this when:
Data changes frequently and cache hit rate would be <50%
Application has strict real-time data requirements (< 1s staleness)
Database is already fast enough (<10ms query latency)
You lack cache invalidation strategy (stale data risk)
Small dataset fits entirely in database memory (shared_buffers)
"""
Set value in both cache layers.
Args:
key: Cache key
value: Value to cache
l1_ttl: L1 TTL override (seconds)
l2_ttl: L2 TTL override (seconds)
Returns:
True if successful
"""
if
not
self
return
False
try
# Store in L1 cache
self
# Store in L2 cache (Redis)
or
self
self
f"Cached: {key} (TTL: {ttl}s)"
return
True
except
as
f"Failed to cache {key}: {e}"
self
'errors'
1
return
False
def
delete
self, key: str
bool
"""
Delete key from both cache layers.
Args:
key: Cache key to delete
Returns:
True if successful
"""
if
not
self
return
False
try
# Delete from L1
self
None
# Delete from L2
self
f"Invalidated cache: {key}"
return
True
except
as
f"Failed to delete {key}: {e}"
self
'errors'
1
return
False
def
delete_pattern
self, pattern: str
int
"""
Delete all keys matching pattern (L2 only).
Args:
pattern: Redis key pattern (e.g., 'user:123:*')
Returns:
Number of keys deleted
"""
"""
Get cache performance metrics.
Returns:
Dictionary with hit rates and counts
"""
self
'l1_hits'
self
'l1_misses'
self
'l2_hits'
self
'l2_misses'
self
'l1_hits'
100
if
0
else
0
self
'l2_hits'
100
if
0
else
0
self
'l1_hits'
self
'l2_hits'
100
if
0
else
0
return
'l1_hits'
self
'l1_hits'
'l1_misses'
self
'l1_misses'
'l1_hit_rate'
round
2
'l2_hits'
self
'l2_hits'
'l2_misses'
self
'l2_misses'
'l2_hit_rate'
round
2
'overall_hit_rate'
round
2
'db_queries'
self
'db_queries'
'errors'
self
'errors'
# Global cache instance
def
cached
prefix: str,
l2_ttl: int = 3600,
invalidate_on_update: bool = False
"""
Decorator to automatically cache function results.
Args:
prefix: Cache key prefix
l2_ttl: Redis cache TTL (seconds)
invalidate_on_update: Auto-invalidate on data updates
Usage:
@cached('user:profile', l2_ttl=1800)
def get_user_profile(user_id: int):
return db.query(...).fetchone()
"""
def
decorator
func: Callable
Callable
@wraps(func)
def
wrapper
*args, **kwargs
# Generate cache key
# Try to get from cache
if
is
not
None
return
# Cache miss - call function
'db_queries'
1
# Cache result
set
return
return
return
# Example usage with database queries
@cached('user:profile', l2_ttl=1800)
def
get_user_profile
user_id: int
"""
Get user profile with automatic caching.
First call: Database query (50ms)
Subsequent calls: L1 cache (1ms) or L2 cache (5ms)
"""
import
"postgresql://..."
with
as
"SELECT * FROM users WHERE id = %s"
return
@cached('user:orders', l2_ttl=600)
def
get_user_orders
user_id: int, limit: int = 10
"""Get user orders with caching."""
import
"postgresql://..."
with
as
"SELECT * FROM orders WHERE user_id = %s ORDER BY created_at DESC LIMIT %s"
return
def
invalidate_user_cache
user_id: int
"""
Invalidate all cached data for a user.
Call this after updating user data:
- User profile updates
- User orders/transactions
- User preferences
"""
f"user:{user_id}:*"
# Example: Invalidate cache on database update
def
update_user_profile
user_id: int, **updates
"""Update user profile and invalidate cache."""
import
"postgresql://..."
with
as
# Update database
", "
f"{k} = %s"
for
in
f"UPDATE users SET {set_clause} WHERE id = %s"
# Invalidate cached data
f"Updated and invalidated cache for user {user_id}"