import CacheStore from '../cache/CacheStore'; import Session from './Session'; import SessionStore from './SessionStore'; export default class CacheBasedSessionStore implements SessionStore { _cache: CacheStore; // The number of minutes to store the data in the session. _expiresIn: number; constructor(cache: CacheStore, expiresIn?: number) { this._cache = cache; this._expiresIn = expiresIn || 0; } async init(): Promise { return this; } async read(key: string): Promise { return this._cache.get(key) as Promise; } async all(): Promise { return this._cache.all() as Promise; } async write(key: string, sess: Session): Promise { return this._cache.put(key, sess, this._expiresIn); } async destroy(key: string): Promise { return this._cache.forget(key); } }