File system cache implementation that stores cache entries as JSON files. Each cache entry is stored as a separate file in the specified directory.

const cache = new FileSystemCache<string>({
cacheDir: '/tmp/my-cache',
defaultTtl: 5000,
verbose: true,
logPrefix: '[FileCache]',
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

  • BaseCache<T>
    • FileSystemCache

Constructors

Properties

Cache configuration

logger: any

Methods

  • Protected

    Builds a full cache key by combining prefix, namespace, and the provided key.

    Parameters

    • key: string

      The base cache key

    Returns string

    The fully qualified cache key

  • Protected

    Creates a cache entry with metadata and expiration information.

    Type Parameters

    • U

      The type of the value being cached

    Parameters

    Returns node.common.apis.cache.CacheEntry<U>

    A complete cache entry object

  • Removes a specific key from the cache.

    Parameters

    • key: string

      The cache key to delete

    Returns Promise<boolean>

    True if the key was successfully deleted

  • Retrieves a value from the file system cache.

    Parameters

    • key: string

      The cache key to retrieve

    Returns Promise<null | T>

    The cached value or null if not found or expired

  • Checks if a key exists in the cache and is not expired.

    Parameters

    • key: string

      The cache key to check

    Returns Promise<boolean>

    True if the key exists and is valid

  • Protected

    Checks if a cache entry has expired based on its expiration timestamp.

    Parameters

    Returns boolean

    True if the entry has expired

  • 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

  • Resets all cache statistics to zero.

    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