@curveball/session
Version:
Session storage using HTTP cookies
51 lines (50 loc) • 1.47 kB
TypeScript
import { SessionStore, SessionValues } from './types.js';
type SessionData = [
number,
SessionValues
];
/**
* The in-memory session store keeps every session into memory.
*
* This has a few major effects:
*
* 1. If the server restarts, all sessions are gone.
* 2. This only ever works with one server. If you need to scale, you need
* a different store.
* 3. It's also leaky in terms of memory. Many active sessions means higher
* memory usage.
*
* This session store is great for very small scales and testing. You can
* easily get going with the memory store, and upgrade to a different one
* when you need it.
*/
export default class MemoryStore implements SessionStore {
/**
* Data goes here
*/
store: Map<string, SessionData>;
/** Stores the timeout ID for the garbage collector */
timeoutId: NodeJS.Timeout | null;
constructor();
set(id: string, values: SessionValues, expire: number): Promise<void>;
get(id: string): Promise<SessionValues | null>;
delete(id: string): Promise<void>;
newSessionId(): Promise<string>;
/**
* Garbage collector.
*
* Loops through sessions and removes all expired sessions.
*/
gc(): void;
/**
* Schedules the garbage collector.
*
* By default it runs every 600 seconds.
*/
scheduleGc(interval?: number): void;
/**
* Cancels the garbage collection scheduler
*/
close(): void;
}
export {};