Session Storage
PlainSessionStorageDriver
The session-storage variant of the plain driver. Same contract, same envelope, same TTL — but backed by window.sessionStorage instead of localStorage. Values disappear when the tab closes.
Signature
import { PlainSessionStorageDriver } from "@mongez/cache";
class PlainSessionStorageDriver extends BaseCacheEngine implements CacheDriverInterface { public storage: Storage; // = sessionStorage}Usage
import { PlainSessionStorageDriver, setCacheConfigurations } from "@mongez/cache";
setCacheConfigurations({ driver: new PlainSessionStorageDriver(),});
cache.set("scroll.y", 312);cache.set("draft", { title: "", body: "Half-written..." });
cache.get("scroll.y"); // 312Everything in local-storage.md applies — the envelope format, TTL behavior, corruption recovery, prefix handling, and SSR caveats are identical. Only the backing storage differs.
Gotchas
- Tabs are isolated. Two tabs of the same site each have their own
sessionStorage. Two tabs of the samelocalStorageshare data; two tabs of the samesessionStoragedon’t. clear()is not prefix-scoped. Same as the local-storage driver — wipes the entire session storage backend for the origin.sessionStoragealso has a ~5MB cap. Same quota behavior as localStorage.