zibri
    Preparing search index...

    Interface CacheInterface<K, V, CacheTag, WriteResultAvailable, N>

    Definition for a cache.

    interface CacheInterface<
        K,
        V,
        CacheTag extends string,
        WriteResultAvailable extends boolean,
        N extends string,
    > {
        _writeResultAvailable: WriteResultAvailable;
        defaultTtl?: number | (() => number | Promise<number>);
        name: N;
        onInvalidationFailure?: OnInvalidationFailure;
        setDirect: (
            key: K,
            value: V,
            options?: CacheSetDirectOptions<CacheTag>,
        ) => Promise<void>;
        store: CacheStoreInterface<K, V>;
        tags: "all" | readonly CacheTagMatcher[];
        wrap: <TArgs extends unknown[]>(
            fn: (...args: TArgs) => V | Promise<V>,
            keyFn: CacheKeyProvider<K, TArgs>,
            options?: CacheWrapOptions<V, TArgs, CacheTag>,
        ) => (...args: TArgs) => Promise<V>;
        wrapDelete: <TReturn, TArgs extends unknown[]>(
            fn: (...args: TArgs) => TReturn | Promise<TReturn>,
            keyFn: CacheKeyProvider<K, TArgs>,
            options?: CacheWrapDeleteOptions<TArgs, CacheTag>,
        ) => (...args: TArgs) => Promise<TReturn>;
        wrapInvalidate: <TReturn, TArgs extends unknown[]>(
            fn: (...args: TArgs) => TReturn | Promise<TReturn>,
            options: CacheWrapInvalidateOptions<TArgs, CacheTag>,
        ) => (...args: TArgs) => Promise<TReturn>;
        wrapWrite: <TArgs extends unknown[]>(
            fn: (...args: TArgs) => V | Promise<V>,
            keyFn: WriteResultAvailable extends true
                ? ResultCacheKeyProvider<K, V, TArgs>
                : CacheKeyProvider<K, TArgs>,
            options?: WriteResultAvailable extends true
                ? CacheWrapWriteOptionsWithResult<V, TArgs, CacheTag>
                : CacheWrapWriteOptionsArgsOnly<TArgs, CacheTag>,
        ) => (...args: TArgs) => Promise<V>;
    }

    Type Parameters

    • K
    • V
    • CacheTag extends string
    • WriteResultAvailable extends boolean
    • N extends string

    Implemented by

    Index

    Properties

    _writeResultAvailable: WriteResultAvailable

    Phantom carrier, only for type inference.

    defaultTtl?: number | (() => number | Promise<number>)

    The default time to live for a cached value.

    name: N

    The name of the cache. Should be unique.

    onInvalidationFailure?: OnInvalidationFailure

    Whether to throw when invalidation fails or to just log and ignore.

    setDirect: (
        key: K,
        value: V,
        options?: CacheSetDirectOptions<CacheTag>,
    ) => Promise<void>

    Directly write a value into this cache, following its configured write strategy.

    Use this instead of wrapWrite when the source function has already been called and you only need to propagate the result.

    The store used by this cache.

    tags: "all" | readonly CacheTagMatcher[]

    The tags that any values inside of this cache might have.

    This is used for performance improvements, to skip caches for invalidateTags if the given tag will never be inside any of the cached values. Can be set to 'all' to check every time.

    wrap: <TArgs extends unknown[]>(
        fn: (...args: TArgs) => V | Promise<V>,
        keyFn: CacheKeyProvider<K, TArgs>,
        options?: CacheWrapOptions<V, TArgs, CacheTag>,
    ) => (...args: TArgs) => Promise<V>

    Returns a cached value if present; otherwise calls fn. The exact caching behavior (whether the result is stored) depends on the concrete strategy.

    wrapDelete: <TReturn, TArgs extends unknown[]>(
        fn: (...args: TArgs) => TReturn | Promise<TReturn>,
        keyFn: CacheKeyProvider<K, TArgs>,
        options?: CacheWrapDeleteOptions<TArgs, CacheTag>,
    ) => (...args: TArgs) => Promise<TReturn>

    Returns a wrapped version of fn that invalidates a cache entry after call.

    wrapInvalidate: <TReturn, TArgs extends unknown[]>(
        fn: (...args: TArgs) => TReturn | Promise<TReturn>,
        options: CacheWrapInvalidateOptions<TArgs, CacheTag>,
    ) => (...args: TArgs) => Promise<TReturn>

    Calls fn → Invalidates tags → Returns the fn result. For operations that affect cached data but produce no cacheable result, e.g. CreateAll/updateAll on a collection cache where no filter key can be derived from the output.

    wrapWrite: <TArgs extends unknown[]>(
        fn: (...args: TArgs) => V | Promise<V>,
        keyFn: WriteResultAvailable extends true
            ? ResultCacheKeyProvider<K, V, TArgs>
            : CacheKeyProvider<K, TArgs>,
        options?: WriteResultAvailable extends true
            ? CacheWrapWriteOptionsWithResult<V, TArgs, CacheTag>
            : CacheWrapWriteOptionsArgsOnly<TArgs, CacheTag>,
    ) => (...args: TArgs) => Promise<V>

    Returns a wrapped version of fn that writes its result into the cache. Key is derived from the result, not the args — handles the create-with-generated-id case cleanly.