Core - v1.0.0
    Preparing search index...

    Interface CacheStore<TRuntime>

    A key-value cache holding JSON-serialisable values under a lifetime.

    A cache is optional infrastructure by definition: an implementation whose Capability.isAvailable is false must read as a miss and drop writes rather than throwing, so a deployment without one runs slower instead of failing. That is a requirement on every implementation, not an accident of one of them — a caller that branched on it would defeat the point.

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    interface CacheStore<TRuntime = unknown> {
        get<T = unknown>(runtime: TRuntime, key: string): Promise<T>;
        isAvailable(runtime: TRuntime): boolean;
        keys(runtime: TRuntime, prefix: string): Promise<string[]>;
        remember<T>(
            runtime: TRuntime,
            key: string,
            load: () => Promise<T>,
            ttl?: number,
        ): Promise<T>;
        remove(runtime: TRuntime, key: string): Promise<void>;
        set(
            runtime: TRuntime,
            key: string,
            value: unknown,
            ttl?: number,
        ): Promise<void>;
    }

    Type Parameters

    • TRuntime = unknown

      The runtime handle the cache is resolved from.

    Hierarchy (View Summary)

    Implemented by

    Index
    • Reads a cached value.

      Type Parameters

      • T = unknown

      Parameters

      • runtime: TRuntime

        The runtime handle.

      • key: string

        The cache key.

      Returns Promise<T>

      The value, or null on a miss or an unavailable cache.

    • Reports whether the capability is actually usable on this runtime.

      Parameters

      Returns boolean

      true when calls will reach a real backing resource.

      A capability backed by an optional resource answers false when that resource was never provisioned. Implementations must document what each method does in that state — degrade or throw — and must not vary it, since a caller choosing between two implementations is relying on the answer meaning the same thing in both.

    • Lists the keys under a prefix.

      Parameters

      • runtime: TRuntime

        The runtime handle.

      • prefix: string

        The key prefix to match.

      Returns Promise<string[]>

      The matched key names.

    • Returns a cached value, computing and caching it on a miss.

      Type Parameters

      • T

      Parameters

      • runtime: TRuntime

        The runtime handle.

      • key: string

        The cache key.

      • load: () => Promise<T>

        Computes the value when the cache misses.

      • Optionalttl: number

        Lifetime in seconds. Falls back to the configured default.

      Returns Promise<T>

      The cached or freshly computed value.

      The read-through pattern most callers actually want — one call instead of a get, a branch, and a set. On an unavailable cache this still returns the computed value; only the caching is skipped.

    • Drops a cached value. Removing a key that was never written is not an error.

      Parameters

      • runtime: TRuntime

        The runtime handle.

      • key: string

        The cache key.

      Returns Promise<void>

    • Writes a value.

      Parameters

      • runtime: TRuntime

        The runtime handle.

      • key: string

        The cache key.

      • value: unknown

        The value to store.

      • Optionalttl: number

        Lifetime in seconds. Falls back to the configured default.

      Returns Promise<void>