Libraries
    Preparing search index...
    • Creates a throttling cache middleware.

      Successful GET responses are cached for a configurable TTL (throttle). Subsequent requests with the same key within the TTL receive a cloned cached response without hitting the network.

      Parameters

      Returns Middleware

      A Middleware that caches responses.

      // 2-second TTL with cache invalidation on mutations:
      const client = createClient(api, {
      middlewares: [throttlingCache({
      throttle: 2000,
      invalidate: (_url, _init, meta) => {
      if (meta && meta.method !== 'GET')
      return `GET@${meta.collectionPath}`;
      return null;
      },
      })],
      });