Class QueryCache

A class to manage caching of query results.

This class provides functionality to cache query results, invalidate cached items based on tags, and retrieve cached items. It relies on a cache service for the actual storage and retrieval of cache entries.

Hierarchy

  • QueryCache

Constructors

Properties

_cacheService: CacheService
_defaultTTL: number
_runtimeConfig: RuntimeConfig

Methods

  • Generates a unique cache key based on a full query and its variables.

    This method creates a UUIDv5 hash as a key for caching the full response of a query based on its query string, variables, and access keys. The key is constructed from a sorted JSON string of these components.

    Returns

    A UUIDv5 hash as a cache key.

    Parameters

    • query: string

      The query string to be executed.

    • variables: Record<string, unknown>

      The variables applied to the query.

    • accessKeys: string[]

      Access keys of the user executing the query.

    Returns string

  • Retrieves a cached value given a cache key.

    This method checks whether the cached item is valid by comparing its timestamp with that of any invalidation tags. If any tag has been modified after the item was cached, the item is treated as invalid and removed.

    Returns

    A promise that resolves to the cached value or null if not found or invalidated.

    Parameters

    • tenantId: string

      Identifier of the tenant accessing the cache.

    • cacheKey: string

      The cache key to look up.

    Returns Promise<any>

  • Invalidates cache entries associated with a specific tag.

    This method updates the timestamp for a given tag, setting it to the current date and time, which will invalidate any cache entries linked to this tag if they were cached before this timestamp.

    Returns

    A promise that resolves once the invalidation is complete.

    Parameters

    • tenantId: string

      Identifier of the tenant.

    • tag: string

      The tag to invalidate.

    Returns Promise<void>

  • Stores data in the cache with a specified key and optional tags.

    This method caches data with a key that includes the tenant id as a prefix, along with an optional list of tags that can be used for later invalidation. The data is stored with a default TTL value.

    Returns

    A promise that resolves when the cache operation is complete.

    Parameters

    • tenantId: string

      Identifier of the tenant for which to cache the data.

    • cacheKey: string

      The key under which to store the data.

    • data: unknown

      The actual data to be cached.

    • tags: string[] = []

      An optional array of tags for easy invalidation. Defaults to an empty array.

    Returns Promise<void>

Generated using TypeDoc