Abstract base class providing common functionality for cache implementations. Handles statistics tracking, key building, entry creation, and logging.

class FileCache extends BaseCache<string> {
constructor(config?: CacheConfig) {
super({ logPrefix: '[FileCache]', ...config });
}
// Implement abstract methods...
}

Type Parameters

  • T = any

    The type of values stored in the cache

Hierarchy (view full)

Implements

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

  • Removes a specific key from the cache. Must be implemented by concrete cache classes.

    Parameters

    • key: string

      The cache key to delete

    Returns Promise<boolean>

    True if the key was successfully deleted

  • Retrieves a value from the cache by key. Must be implemented by concrete cache classes.

    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. Must be implemented by concrete cache classes.

    Parameters

    • key: string

      The cache key to check

    Returns Promise<boolean>

    True if the key exists and is valid

  • Protected

    Logs a message if verbose logging is enabled.

    Parameters

    • message: string

      The log message

    • Optionaldata: any

      Optional additional data to log

    Returns void

  • Stores a value in the cache with optional configuration. Must be implemented by concrete cache classes.

    Parameters

    • key: string

      The cache key to store under

    • value: T

      The value to cache

    • Optionaloptions: common.apis.cache.CacheSetOptions

      Optional caching configuration (TTL, metadata)

    Returns Promise<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