Logos DX
    Preparing search index...

    Function cachePlugin

    • Factory function that creates a cache plugin for FetchEngine.

      The plugin creates its own SingleFlight for cache storage and installs beforeRequest (priority -20) and afterRequest (priority -10) hooks.

      Type Parameters

      • H = unknown
      • P = unknown
      • S = unknown

      Parameters

      Returns FetchPlugin<H, P, S> & {
          flight: SingleFlight<unknown>;
          policy: CachePolicy<S, H, P>;
          clearCache(): void;
          clearCacheKey(key: string): Promise<boolean>;
          deleteCache(key: string): Promise<boolean>;
          invalidateCache(predicate: (key: string) => boolean): Promise<number>;
          invalidatePath(
              pattern: string | RegExp | ((key: string) => boolean),
          ): Promise<number>;
          stats(): { cacheSize: number; inflightCount: number };
      }

      Object with FetchPlugin interface plus cache management methods

      const cache = cachePlugin({ ttl: 300000, staleIn: 60000 });
      const api = new FetchEngine({
      baseUrl: 'https://api.example.com',
      plugins: [cache]
      });

      // Access cache methods directly on the plugin
      cache.clearCache();
      cache.stats();