class MemoryStore
implements CacheStore
Since 0.1.0

In-memory cache implementation with LRU eviction and lazy TTL expiry.

On get of a live entry, the entry is deleted and re-inserted (moves to MRU position). On set, if the map exceeds maxSize, the oldest entry (first Map key) is evicted. Expired entries are lazily deleted on read (get/has).

The constructor accepts a prefix for interface parity with other backends, but MemoryStore intentionally does not use it: each plugin instance owns its own Map, so emptying it in clear() naturally scopes to this instance.

Constructors

MemoryStore(
_prefix: string,
options?: { maxSize?: number | undefined; clock?: ClockFn | undefined; }
)
Parameters
_prefix: string
optional
options: { maxSize?: number | undefined; clock?: ClockFn | undefined; }

Configuration

Methods

clear(): Promise<void>

Remove all entries scoped to this backend's prefix.

The prefix is provided at construction time (not per-call), so each backend can scope the clear appropriately:

  • Redis: SCAN MATCH ${prefix}* + batch DEL
  • Memory: empty the internal map (each plugin instance owns its own map, so it naturally holds only this prefix's keys)
connect(): Promise<void>

Establish the backend connection (if applicable).

delete(key: string): Promise<boolean>

Delete a value. The key is already-prefixed by CacheService.

disconnect(): Promise<void>

Gracefully disconnect.

get<T>(key: string): Promise<T | null>

Read a value. The key is already-prefixed by CacheService.

has(key: string): Promise<boolean>

Check existence. The key is already-prefixed by CacheService.

Since 0.5.0
isHealthy(): Promise<boolean>

Lifecycle truth (M90b): an in-process Map has no separate backend to reach, so reachability IS readiness — the process either holds the map or it does not.

isReady(): boolean

Reports whether the backend is ready for operations.

set<T>(
key: string,
value: T,
ttlSeconds?: number
): Promise<void>

Write a value. The key is already-prefixed by CacheService.

Usage

import { MemoryStore } from "cache-plugin/src/index.ts";