@tinkoff/request

@tinkoff/request

  • How to
  • Plugins
  • Internals
  • GitHub

›Plugins

Core

  • Core
  • Context
  • Request execution
  • Plugin

Plugins

  • Plugins
  • Batch
  • Cache - Deduplicate
  • Cache - Fallback
  • Cache - Memory
  • Cache - Etag
  • Cache - Persistent
  • Log
  • Protocol - Http
  • Protocol - Jsonp
  • Transform - Url
  • Validate
  • Circuit Breaker
  • Prom RED metrics
  • Retry

How to

  • How to

Cache Plugin - Deduplicate

Deduplicate requests with equal cache keys before making a request. If plugin is executed it will check all currently running requests, all requests with equal cache key will transform into single request, and resolve or reject accordingly to that single request.

Parameters

Create options

  • getCacheKey: function [=see @tinkoff/request-cache-utils] - function used for generate cache key
  • shouldExecute: boolean [=true] - plugin enable flag

Request params

  • cache: boolean [=true] - should any cache plugin be executed.
  • deduplicateCache: boolean [=true] - should this specific cache plugin be executed

External meta

  • cache.deduplicated: boolean - flag indicating that current request has been deduplicated

Example

import request from '@tinkoff/request-core';
import deduplicateCache from '@tinkoff/request-plugin-cache-deduplicate';

const req = request([
    // ...plugins for any request transforms
    // should be set after transforming plugins and before any other heavy plugins
    deduplicateCache(),
    // should be set before protocol plugins or other heavy cache plugins
    // ...plugins for making actual request
]);

req({url: 'test1'}) 
req({url: 'test1'}) // this request will be deduplicated in prior of first one
req({url: 'test2'}) // cacheKey for that request by default is differ, so another request will be send

← BatchCache - Fallback →
  • Parameters
    • Create options
    • Request params
    • External meta
  • Example
Copyright © 2023 tinkoff.ru