Cache and Sessions
Cache-aside pattern
App checks Redis first; on a miss, load from the database, then SET with a TTL.
GET cache:product:42
# miss -> query DB, then:
SET cache:product:42 "{\"name\":\"Tee\"}" EX 300
Invalidate on write
When the source data changes, delete or overwrite the cache key so readers do not see stale values forever.
DEL cache:product:42
Sessions
Store a session id in a cookie; keep session data in Redis with an expiry matching idle timeout.
SET session:S3cr3t "{\"userId\":7}" EX 86400
GET session:S3cr3t
Keep payloads lean
Cache only what you need. Huge values waste memory and network. Prefer hashes or compact JSON.
Comments
One comment per signed-in account. Comments are saved with this page’s URL.