4.3.6 Application-Level Caching
Implement Application-Level Caching
Caching Layers
Client → CloudFront (edge)
→ API Gateway (API cache)
→ ElastiCache/DAX (application)
→ Database
Caching Strategies
| Strategy | Pros | Cons |
|---|
| Lazy Loading | Only cache requested data | Cache miss penalty, stale data |
| Write-Through | Always fresh | Write penalty, cache churn |
| TTL | Balance freshness/performance | May serve stale briefly |
ElastiCache Redis vs DAX
| Redis | DAX |
|---|
| Latency | Sub-millisecond | Microsecond |
| Use case | General caching, sessions | DynamoDB only |
| Data types | Complex (sets, lists) | DynamoDB compatible |
| API change | Yes (Redis client) | Minimal (same DynamoDB API) |
DAX Integration
import amazondax
dax = amazondax.AmazonDaxClient(
endpoints=['dax-cluster.abc.dax-clusters.us-east-1.amazonaws.com:8111']
)
# Same API as DynamoDB
response = dax.get_item(TableName='Orders', Key={'id': {'S': '123'}})
Exam Tip: DAX = DynamoDB only, microsecond, API compatible. Redis = versatile. Lazy Loading + TTL = most common combo.