@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 - Persistent

!Executes only in browser, for server this plugin is noop.

Caches requests result into IndexedDB. Uses library idb-keyval as wrapper to IndexedDB.

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.
  • cacheForce: boolean [=false] - when enabled all cache plugin will be executed only on complete status (request wont be resolved with cache value in that case and will only store result cache on completed requests)
  • persistentCache: boolean [=true] - should this specific cache plugin be executed
  • persistentCacheForce: boolean [=false] - specific case of cacheForce for this plugin only.

External meta

  • cache.persistentCache: boolean - flag indicating that current request has been returned from persistent cache

Example

import request from '@tinkoff/request-core';
import persistentCache from '@tinkoff/request-plugin-cache-persistent';

const req = request([
    // ...plugins for any request transforms
    // should be set after transforming plugins and before other more lightweighted cache plugins
    persistentCache(),
    // should be set before protocol plugins or other heavy cache plugins
    // ...plugins for making actual request
]);
← Cache - EtagLog →
  • Parameters
    • Create options
    • Request params
    • External meta
  • Example
Copyright © 2023 tinkoff.ru