Memcached is a simple in-memory key-value store. It is useful as a cache when an application can retrieve the original data elsewhere. A web application, for example, can cache the result of a SQL query while the relational database remains the source of truth. section 11.2.1 section 11.7
For a database-backed cache:
- Choose a key, such as the SQL query, and ask the cache for its result. section 11.0
- If the result is missing, read it from the database and store it in the cache. The query cache needs only simple operations such as GET and SET. section 11.0 section 11.2.1
- Plan how cached values stay current: items can expire, or the application can use a write-through strategy. section 11.7
Amazon ElastiCache runs Memcached as a managed cluster of 1–40 nodes. The client typically uses consistent hashing to decide which node holds each key; every node stores a distinct portion of the keys. Adding nodes can increase available memory and throughput. Cluster nodes can be placed across multiple subnets for availability. section 11.2.1 section 11.7
The cluster diagram shows how clients reach the nodes that hold cached data. section 11.2.1
Choose Memcached when the application needs a simple cache and can tolerate losing cached data: a failed node is replaced, but its data is lost. Memcached has no backup or replication in this deployment and does not provide user authentication. Use IAM to control cluster administration and security groups to restrict network traffic to its nodes. If backup, replication, or more complex data structures are required, compare the Redis deployment options instead. section 11.2 section 11.2.1 section 11.3 section 11.3.3
