Skip to main content

SessionCacheStrategy

This strategy defines how sessions get cached. Since most requests will need the Session object for permissions data, it can become a bottleneck to go to the database and do a multi-join SQL query each time. Therefore, we cache the session data only perform the SQL query once and upon invalidation of the cache.

The Vendure default from v3.1+ is to use a the DefaultSessionCacheStrategy, which delegates to the configured CacheStrategy to store the session data. This should be suitable for most use-cases.

Note

If you are using v3.1 or later, you should not normally need to implement a custom SessionCacheStrategy, since this is now handled by the DefaultSessionCacheStrategy.

Prior to v3.1, the default was to use the InMemorySessionCacheStrategy, which is fast but suitable for single-instance deployments.

Info

This is configured via the authOptions.sessionCacheStrategy property of your VendureConfig.

Here's an example implementation using Redis. To use this, you need to add the ioredis package as a dependency.

Example

Ts
Signature

set

method(session: CachedSession) => void | Promise<void>

Store the session in the cache. When caching a session, the data should not be modified apart from performing any transforms needed to get it into a state to be stored, e.g. JSON.stringify().

get

method(sessionToken: string) => CachedSession | undefined | Promise<CachedSession | undefined>

Retrieve the session from the cache

delete

method(sessionToken: string) => void | Promise<void>

Delete a session from the cache

clear

method() => void | Promise<void>

Clear the entire cache

A simplified representation of the User associated with the current Session.

Signature

id

propertyID

identifier

propertystring

verified

propertyboolean

channelPermissions

propertyUserChannelPermissions[]

A simplified representation of a Session which is easy to store.

Signature

cacheExpiry

propertynumber

The timestamp after which this cache entry is considered stale and a fresh copy of the data will be set. Based on the sessionCacheTTL option.

id

propertyID

token

propertystring

expires

propertyDate

activeOrderId

propertyID

authenticationStrategy

propertystring

user

activeChannelId

propertyID
Was this chapter helpful?
Report Issue
Edited Feb 25, 2026ยทEdit this page