ThemeParks.wiki Parks API - v2.0.0
    Preparing search index...

    Class CacheLib

    Index
    • Remove all expired entries from cache

      Returns number

    • Delete cached entries.

      Like clearByClassName, this is a re-fetch and steps over persistent operational state (see cacheKeys.ts). The broad gesture is the one an operator reaches for when a symptom spans several destinations, which is exactly when quietly discarding what we have observed does the most damage. Pass includePersistent for a genuine full wipe.

      Parameters

      • __namedParameters: { includePersistent?: boolean } = {}

      Returns void

    • Delete cached entries across every destination. Returns number deleted.

      Steps over persistent operational state for the same reason clearByClassName does; pass includePersistent for a full wipe.

      Parameters

      • __namedParameters: { includePersistent?: boolean } = {}

      Returns number

    • Delete all cache entries whose key contains the given class name. Matches both plain keys (ClassName:method:args) and prefixed keys (prefix:ClassName:method:args). Returns the number of deleted entries.

      Keys carrying a PERSISTENT_KEY_FRAGMENTS fragment are stepped over: this call means "refetch from upstream", not "forget what we have observed". Pass includePersistent to sweep those too, which is a full reset of the destination rather than a flush, and is what test setup wants.

      Parameters

      • className: string
      • __namedParameters: { includePersistent?: boolean } = {}

      Returns number

    • Targeted flush: delete one class's live cache rows whose key contains a substring. For operator tooling that needs to drop one stale value, such as a cached upstream version, without refetching everything the class holds.

      Differences from clearByClassName, all deliberate:

      • A row must also contain contains. Matching is literal (_ and % are not wildcards) and case-sensitive, class name included, where clearByClassName ignores case. A class is matched the same two ways: Class:... and prefix:Class:.... The substring is tested against the class name and arguments, so a short or common one reaches far: pair it with maxRows.
      • For an HTTP-layer key (Class:VERB:url:{headers}:body) only the class, the verb and the URL up to its query string are searchable. Headers, query and body can carry credentials, and a match count would let a caller recover one a character at a time. A method argument that is itself a secret is still searchable in a decorated method's key, so rate-limit untrusted callers.
      • Persistent operational state is always stepped over, counted as neither matched nor cleared. There is no includePersistent: this is a flush, never a reset.
      • Only live rows count. An expired row is already unreachable.
      • maxRows makes the call refuse rather than delete a surprising amount: when more rows match, nothing is deleted and capped is true.
      • It throws on bad arguments and on a database error instead of returning 0, because "nothing was cleared" and "the clear failed" must not look alike.
      • The count and the delete run in one transaction, so what was counted is exactly what is deleted.

      The result never contains a raw key (see ClearMatchingResult); a group label is the class plus the identifier-shaped segment after it, which is a method name or HTTP verb for every key the decorators build. Only this process's stored rows are touched. A fetch already in flight when the delete runs can store its result again afterwards, and a value memoised in memory rather than in this cache is not affected.

      It only reaches keys that carry the class name. A row stored under a fixed key (@cache({key: 'someConstant'})) has no class segment, so remove it with an exact CacheLib.delete.

      A large match set is deleted row by row inside the transaction: tens of thousands of rows stall the event loop for seconds and hold the write lock, so set maxRows.

      Parameters

      Returns ClearMatchingResult

    • Parameters

      • key: string

      Returns void

    • Enable temporary mode - use in-memory cache that doesn't persist Must be called before any cache operations

      Returns void

    • Enforce cache size limit by removing least recently accessed entries. Called periodically from set() rather than on every write.

      Returns void

    • When the entry under key expires, as a millisecond timestamp. Null when there is no live entry.

      Parameters

      • key: string

      Returns number | null

    • Parameters

      • key: string

      Returns any

    • Get all cache entries with metadata

      Returns {
          expiresAt: number;
          isExpired: boolean;
          key: string;
          lastAccess: number;
          size: number;
          value: any;
      }[]

    • Parameters

      • key: string

      Returns boolean

    • Check if cache is in temporary mode

      Returns boolean

    • Type Parameters

      • T

      Parameters

      • key: string
      • value: T
      • ttlSeconds: number = 60

      Returns void

    • Start automatic cleanup of expired entries

      Returns void

    • Get cache statistics

      Returns { active: number; expired: number; total: number }

    • Stop automatic cleanup

      Returns void

    • Cache-with-dedup wrapper. Concurrent callers on a cache miss for the same key share a single execution rather than each running fn independently.

      Type Parameters

      • T

      Parameters

      • key: string
      • fn: () => T | Promise<T>
      • ttl: number | ((result: T) => number | Promise<number>)

        Either a fixed TTL in seconds, or a callback that derives a TTL from the function's result (e.g. for OAuth tokens that expire on a server-supplied schedule).

      • Optionalcaller: () => Omit<HttpCaller, "retryCount">

        Returns who calls, for the method cache observer (see setMethodCacheObserver). Called only on a hit while an observer is set.

      Returns Promise<T>