@thi.ng/server
Version:
Minimal HTTP server with declarative routing, static file serving and freely extensible via pre/post interceptors
35 lines (34 loc) • 663 B
JavaScript
import { TLRUCache } from "@thi.ng/cache";
class InMemorySessionStore {
ttl;
sessions;
constructor({
ttl = 3600,
autoExtend = true,
initial
} = {}) {
this.ttl = ttl;
this.sessions = new TLRUCache(
initial ? Object.entries(initial) : null,
{
ttl: ttl * 1e3,
autoExtend
}
);
}
get(id) {
return this.sessions.get(id);
}
set(session) {
this.sessions.set(session.id, session);
return true;
}
delete(id) {
return this.sessions.delete(id);
}
}
const inMemorySessionStore = (opts) => new InMemorySessionStore(opts);
export {
InMemorySessionStore,
inMemorySessionStore
};