Memcache session storage forDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/remix-run/remix/llms.txt
Use this file to discover all available pages before exploring further.
remix/session. Use this package when app servers need to share session state through Memcache.
Installation
Memcache storage uses TCP sockets and requires a Node.js runtime.
API Reference
createMemcacheSessionStorage
Create a Memcache-backed session storage instance.Memcache server address in the format
host:port (e.g., '127.0.0.1:11211')Configuration options
MemcacheSessionStorageOptions
Prefix for all Memcache keys. Defaults to
'remix:session:'.Time-to-live in seconds for sessions. Defaults to
0 (no expiration).Whether to reuse unknown session IDs sent by the client. Defaults to
false.Returns
A SessionStorage instance backed by Memcache
Usage Examples
Basic Setup
Connect to Memcache and create session storage:With Session Middleware
Use with session middleware for automatic session management:Manual Session Management
Manage sessions manually:Production Configuration
Use environment variables for production:Multiple Memcache Servers
For multiple servers, you’ll need to handle connection pooling at a higher level. The storage connects to one server at a time:Session Expiration
Set appropriate TTL to prevent unlimited session growth:Key Prefixes for Isolation
Use key prefixes to isolate sessions from different applications:Environment Variables
Store Memcache configuration in environment variables:.env
Best Practices
- Always set a TTL to prevent unlimited session growth
- Use meaningful key prefixes to organize sessions
- Handle connection errors gracefully
- Set appropriate maxAge on session cookies to match TTL
- Monitor Memcache memory usage and evictions
- Use multiple Memcache servers for redundancy
- Consider Memcache memory limits when sizing sessions
Performance Considerations
- Memcache is very fast for session storage
- Network latency is the primary bottleneck
- Memcache uses LRU eviction when memory is full
- Monitor cache hit rates to ensure adequate memory
- Consider using connection pooling for high-traffic apps
Limitations
- Requires Node.js (uses TCP sockets)
- Sessions may be evicted if Memcache runs out of memory
- No persistence - sessions are lost if Memcache restarts
- Single server connection per storage instance
Related Documentation
Session
Core session API and management
Session Middleware
Automatic session management middleware