SessionCacheStrategy
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.
Signature
interface SessionCacheStrategy extends InjectableStrategy {
set(session: CachedSession): void | Promise<void>;
get(sessionToken: string): CachedSession | undefined | Promise<CachedSession | undefined>;
delete(sessionToken: string): void | Promise<void>;
clear(): void | Promise<void>;
}
Extends
Members
set
method
type:
(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
type:
(sessionToken: string) => CachedSession | undefined | Promise<CachedSession | undefined>
Retrieve the session from the cache
delete
method
type:
(sessionToken: string) => void | Promise<void>
Delete a session from the cache
clear
method
type:
() => void | Promise<void>
Clear the entire cache
CachedSessionUser
A simplified representation of the User associated with the current Session.
Signature
type CachedSessionUser = {
id: ID;
identifier: string;
verified: boolean;
channelPermissions: UserChannelPermissions[];
}
Members
id
property
type:
ID
identifier
property
type:
string
verified
property
type:
boolean
channelPermissions
property
type:
UserChannelPermissions[]
CachedSession
A simplified representation of a Session which is easy to store.
Signature
type CachedSession = {
cacheExpiry: number;
id: ID;
token: string;
expires: Date;
activeOrderId?: ID;
authenticationStrategy?: string;
user?: CachedSessionUser;
activeChannelId?: ID;
}
Members
cacheExpiry
property
type:
number
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
property
type:
ID
token
property
type:
string
expires
property
type:
Date
activeOrderId
property
type:
ID
authenticationStrategy
property
type:
string
user
property
type:
CachedSessionUser
activeChannelId
property
type:
ID