Overview
Memcached is a high-performance, distributed memory caching system. Convox supports both containerized Memcached and AWS ElastiCache-managed instances.Basic Configuration
Define a Memcached resource inconvox.yml:
Containerized Memcached
For development and staging environments, use containerized Memcached:Custom Images
Use custom Memcached images:The
image field allows you to use any compatible Memcached image. Always include an image tag.AWS ElastiCache Memcached
For production workloads requiring horizontal scaling, use AWS ElastiCache:Configuration Options
Required. The number of cache nodes in the Memcached cluster. Memcached scales horizontally by adding nodes.
The compute and memory capacity per cache node. Common values:
cache.t3.micro- 0.5 GiB memorycache.t3.small- 1.37 GiB memorycache.t3.medium- 3.09 GiB memorycache.m5.large- 6.38 GiB memorycache.r5.large- 13.07 GiB memory (memory-optimized)
Memcached engine version (e.g., 1.6.6, 1.6.17)
Prevent accidental deletion of the cache cluster. This is a Convox-managed feature that prevents resource removal even if deleted from
convox.yml.Spread cache nodes across multiple Availability Zones for improved availability
Enable encryption at rest for data stored on disk
Automatically apply minor engine version patches during maintenance windows
ElastiCache cluster ID to import an existing cluster
The
nodes parameter is required for ElastiCache Memcached. Set it to the desired number of cache nodes for your cluster.Advanced Features
Horizontal Scaling
Memcached scales horizontally by adding more nodes:To scale up, increase the
nodes value and redeploy. To scale down, decrease the value. Total cache capacity = (node memory) × (number of nodes).Multi-AZ Deployment
Distribute nodes across Availability Zones for improved availability:Import Existing ElastiCache
Import an existing AWS ElastiCache Memcached cluster:The cluster ID of the existing ElastiCache Memcached cluster
While
import is set, the cache cluster is read-only from Convox’s perspective. Remove import to allow Convox to manage the cluster configuration.Environment Variables
When linked to a service, Memcached resources inject these environment variables:CLI Operations
List Resources
Get Resource Information
Proxy to Memcached
Create a local tunnel to the Memcached cluster:The
proxy command is particularly useful for ElastiCache instances that are not publicly accessible.Connection Examples
- Node.js
- Python
- Ruby
- PHP
Memcached vs Redis
Choose Memcached when:Simple Caching
You need simple key-value storage without complex data structures
Horizontal Scaling
You want to scale by adding more nodes (Memcached’s strength)
Multi-threaded
You want to take advantage of multi-core processors
Large Cache
You need to cache large amounts of data across multiple nodes
Complex Data Types
You need lists, sets, sorted sets, or other data structures
Persistence
You need data persistence or replication
Pub/Sub
You need publish/subscribe messaging patterns
Transactions
You need atomic operations or transactions
Production Best Practices
Enable Deletion Protection
Set
deletionProtection: true to prevent accidental deletion of production cache clusters.Use Multiple Nodes
Deploy at least 2 nodes for better availability and horizontal scaling.
Enable Multi-AZ
Set
durable: true to distribute nodes across Availability Zones.Monitor Memory Usage
Track cache hit rates and memory usage to optimize node count and size.
Common Use Cases
Page Caching
Cache rendered HTML pages to reduce server load and improve response times.
Database Query Cache
Store frequently accessed database query results.
Session Storage
Store user session data across multiple web servers.
API Response Cache
Cache external API responses to reduce latency and API costs.
Example Configurations
- Development
- Staging
- Production