kernl API
    Preparing search index...

    Function attachEventCache

    • Wire a cache to an event store. New events the store receives are written in batches through applesauce's persistEventsToCache, which skips events that came from the cache. cacheRequest is what applesauce loaders take as their cacheRequest: it marks every event it returns as from the cache, and resolves nothing when the cache cannot answer, because a cache is an accelerator, never identity.

      Parameters

      • store: Pick<IEventStoreStreams, "insert$">

        An event store, or anything with its insert$ stream.

      • cache: EventCache

        The cache to write to and read from.

      • options: AttachEventCacheOptions = {}

        batchTime and maxBatchSize for the writes.

      Returns AttachedEventCache

      cacheRequest and stop, which ends the writes.

      import { EventStore } from 'applesauce-core';
      import { attachEventCache, createMemoryCacheAdapter } from '@kernlize/core/cache';

      const store = new EventStore();
      const attached = attachEventCache(store, await createMemoryCacheAdapter().open());
      await attached.cacheRequest([{ kinds: [0], limit: 1 }]);
      attached.stop();