"Slow pages need a bigger database." Often they don't. Most slow apps run the same handful of queries again and again: the product page, the menu, the user's profile. A bigger database answers those repeats a little faster; a cache answers them from memory and lets the database rest. On AWS, that cache is Amazon ElastiCache.
What ElastiCache does
ElastiCache is a managed in-memory data store. Because the data lives in RAM, reads come back in microseconds instead of the milliseconds a disk-based database needs. AWS handles provisioning, patching, monitoring and node replacement.
You can run it two ways:
- Serverless: create a cache by name and ElastiCache scales memory and compute for you.
- Node-based clusters: you choose node types, node count and Availability Zones, for full control.
The cache-aside pattern
The most common way to use it is cache-aside (lazy loading):
- The app asks the cache first.
- Hit: the answer comes straight back.
- Miss: the app reads the database, returns the answer and saves it in the cache with a TTL (time to live).
The TTL is the part people skip. Without it, cached data never refreshes and users see stale prices or menus. Pick a TTL per kind of data: seconds for stock levels, hours for a product description.
Three engines, not two
The classic answer was "Redis or Memcached". That has changed. ElastiCache now supports three engines:
- Valkey: an open-source fork of Redis, run by the Linux Foundation. AWS promotes it and prices it lower: about 33% less on serverless and 20% less on node-based clusters than the other engines, according to the ElastiCache pricing page.
- Redis OSS: the open-source Redis line that ElastiCache has run for years. Existing apps keep working.
- Memcached: the simplest option.
Valkey and Redis OSS speak the same protocol and add replication, automatic failover, backups and rich data types (lists, sets, sorted sets, hashes, pub/sub). Memcached stores plain keys and values, is multithreaded, and has no replication: if a node fails, its data is gone, which is fine for a pure cache you can rebuild.
Rule of thumb: start new caches on Valkey; pick Memcached only when a simple, disposable cache is all you need. Check your client library and engine version before moving an existing Redis OSS cluster.
Where AI fits
LLM calls are slow and billed per token, and users ask the same things over and over. Cache answers so you don't pay for the same prompt twice. An exact-match cache helps with identical prompts. A semantic cache goes further: ElastiCache for Valkey (version 8.2 and later) supports vector search, so you store an embedding of each question with its answer and return the cached answer when a new question means the same thing, even if it is worded differently. AWS publishes a semantic caching guide for this pattern. Set a similarity threshold carefully, and a TTL, so a close-but-different question doesn't get the wrong answer.
Quick recap
- ElastiCache keeps hot answers in memory; check the cache before the database, and always set a TTL.
- Engines today: Valkey (recommended, cheaper), Redis OSS, and Memcached (simple, no replicas).
- For AI apps, Valkey vector search enables semantic caching of model answers.