@thi.ng/server
Version:
Minimal HTTP server with declarative routing, static file serving and freely extensible via pre/post interceptors
41 lines • 1.47 kB
TypeScript
import { TLRUCache } from "@thi.ng/cache";
import type { ISessionStore, ServerSession } from "../api.js";
export interface InMemorySessionOpts<T extends ServerSession = ServerSession> {
/**
* Session timeout in seconds.
*
* @defaultValue 3600
*/
ttl: number;
/**
* If true (default), a session's cache span automatically extends by
* {@link InMemorySessionOpts.ttl} with each request. If false, the session
* auto-expires after TTL since session creation.
*
* @defaultValue true
*/
autoExtend: boolean;
/**
* Initial record of active sessions (none by default).
*/
initial: Record<string, T>;
}
/**
* Session storage implementation for use with {@link sessionInterceptor}, using
* an in-memory TLRU Cache with configurable TTL.
*/
export declare class InMemorySessionStore<T extends ServerSession = ServerSession> implements ISessionStore<T> {
readonly ttl: number;
protected sessions: TLRUCache<string, T>;
constructor({ ttl, autoExtend, initial, }?: Partial<InMemorySessionOpts<T>>);
get(id: string): T | undefined;
set(session: T): boolean;
delete(id: string): boolean;
}
/**
* Factory function for creating a new {@link InMemorySessionStore}.
*
* @param opts
*/
export declare const inMemorySessionStore: <T extends ServerSession = ServerSession>(opts?: Partial<InMemorySessionOpts<T>>) => InMemorySessionStore<T>;
//# sourceMappingURL=memory.d.ts.map