effex-monorepo
    Preparing search index...

    Interface IAsyncCache

    The AsyncCache service interface.

    interface IAsyncCache {
        clear: () => Effect<void>;
        get: <A, E = never, R = never>(
            key: CacheKey,
            fetcher: () => Effect<A, E, R>,
            options?: CacheGetOptions<A>,
        ) => Effect<AsyncReadable<A, E>, never, Scope | R>;
        invalidate: (keyPrefix: CacheKey) => Effect<void>;
        remove: (keyPrefix: CacheKey) => Effect<void>;
    }
    Index

    Properties

    clear: () => Effect<void>

    Remove all entries from the cache.

    get: <A, E = never, R = never>(
        key: CacheKey,
        fetcher: () => Effect<A, E, R>,
        options?: CacheGetOptions<A>,
    ) => Effect<AsyncReadable<A, E>, never, Scope | R>

    Get or create a cached AsyncReadable for the given key.

    If an entry already exists for this exact key, returns it. Otherwise creates a new AsyncReadable, optionally seeded with initialData.

    const cache = yield* AsyncCache;
    const posts = yield* cache.get(
    ['posts'],
    () => Effect.tryPromise(() => fetch('/api/posts').then(r => r.json())),
    { initialData: loaderData.posts }
    );
    invalidate: (keyPrefix: CacheKey) => Effect<void>

    Invalidate all cache entries whose keys match the given prefix. Matching entries are immediately refetched.

    // Invalidate all posts queries
    yield* cache.invalidate(['posts']);

    // Invalidate a specific user's data
    yield* cache.invalidate(['users', userId]);
    remove: (keyPrefix: CacheKey) => Effect<void>

    Remove all cache entries whose keys match the given prefix. Unlike invalidate, this disposes the entries entirely.