A good cache key is unique, readable, and predictable.
Pattern: {entity}:{identifier}:{version}
Examples:
user:12345:profileproduct:abc123:v2timeline:user:12345:page:1
Anti-patterns:
- Using raw SQL as key (hard to invalidate)
- Keys without namespace (collision risk)
- Keys with timestamps (never hit)
Versioning: Include version in key to invalidate entire cache on schema changes. Bump v2 to v3 and old data is ignored.
Document your key naming convention. Inconsistent keys lead to cache misses and debugging nightmares.