In-memory cache implementation using a JavaScript Map. Fast and simple, but data is lost when the process exits.

const cache = new MemoryCache<string>({
defaultTtl: 5000,
verbose: true,
logPrefix: '[EntityCache]',
namespace: 'medical'
});

await cache.set('disease:diabetes', 'Type 2 Diabetes Mellitus');
const result = await cache.get('disease:diabetes');

Type Parameters

  • T = any

    The type of values stored in the cache

Hierarchy (view full)

Constructors

Properties

Cache configuration

logger: any

Methods

  • Returns all keys currently stored in the cache. Filters out expired entries and returns the original keys without prefixes.

    Returns Promise<string[]>

    Array of all cache keys

  • Protected

    Logs a message if verbose logging is enabled.

    Parameters

    • message: string

      The log message

    • Optionaldata: any

      Optional additional data to log

    Returns void

  • Protected

    Updates cache statistics for performance monitoring.

    Parameters

    • operation:
          | "set"
          | "delete"
          | "hit"
          | "miss"

      The type of operation that occurred

    • Optionalcontext: {
          fullKey?: string;
          key?: string;
          reason?: string;
          [key: string]: any;
      }

      Additional context for hit/miss logging

      • [key: string]: any
      • OptionalfullKey?: string
      • Optionalkey?: string
      • Optionalreason?: string

    Returns void