createMemorySessionStorage
Creates a simple in-memory SessionStorage object. This is primarily useful for testing and as a reference implementation. Not suitable for production use beyond a single process.Signature
Configuration options for memory session storage.
The cookie used to store the session ID on the client, or options to create one automatically.
The name of the session ID cookie.
Array of secrets for signing the session ID cookie.
Maximum age of the session in seconds.
Makes cookie inaccessible to JavaScript.
Only send cookie over HTTPS.
Controls cross-site request behavior.
Returns
A session storage object with methods to manage sessions.
Parses the session ID from the Cookie header and returns the session.
Stores session data in memory and returns the Set-Cookie header with the session ID.
Deletes session data from memory and returns a Set-Cookie header that clears the cookie.
Basic Example
filename=app/sessions.server.ts
Testing Example
Use in tests to avoid external dependencies:filename=app/routes/__tests__/auth.test.ts
Development Example
Simplify local development without setting up a database:filename=app/sessions.server.ts
Integration Testing
filename=tests/integration/auth.test.ts
Session Expiration
Memory sessions support expiration:TypeScript Support
Advantages
- Zero dependencies - No database or external services required
- Fast - In-memory operations are extremely fast
- Simple setup - No configuration needed
- Perfect for testing - Isolated sessions per test
- Development friendly - Quick iteration without infrastructure
Limitations
Not Suitable for Production
Memory storage has several critical limitations for production use: Single Process OnlyMemory Leaks
Expired sessions remain in memory until explicitly cleaned:When to Use
Testing
Perfect for unit and integration tests:Local Development
Simplify development environment:Prototyping
Quickly prototype features without infrastructure:Single-User Applications
Acceptable for truly single-user scenarios:Migration to Production Storage
When ready for production, migrate to persistent storage:filename=app/sessions.server.ts
Related
- createSessionStorage - Custom session storage backends
- createCookieSessionStorage - Cookie-based sessions
- Sessions and Cookies - Sessions guide