1.1.11 • Published 7 months ago

memoize-token v1.1.11

Weekly downloads
6
License
MIT
Repository
github
Last release
7 months ago

Last version NPM Status

A memoize library for refreshing and cache token values.

Install

$ npm install memoize-token --save

Usage

const memoizeToken = require('memoize-token')
let value = -1
const values = ['foo', 'bar']

const fn = memoizeToken(
  () => values[++value],
  { max: 2, key: 'test', cache }
)

;(async () => {
  await fn() // => 'foo'
  await fn() // => 'foo'
  await fn() // max excedeed, refresh the token => 'bar'
  await fn() // => 'bar'
})()

API

memoizeToken(fn, options)

fn

Required Type: Function

Function to be memoized and used for refreshing the token.

options

max

Required Type: Number

Maximum numbers of calls after refresh the token.

key

Required Type: String

The base key to use into the cache.

expire

Type: Number

Time in milliseconds to consider a token as expired.

cache

Type: Object Default: new Map()

Use a different cache storage.

Must implement the following methods: .get(key) and .set(key, value), Check keyv to see database connectors.

Related

  • bottleneck – Job scheduler and rate limiter.
  • limiter – Provides a generic rate limiter and token bucket for Node.js.

License

memoize-token © microlink.io, released under the MIT License. Authored and maintained by Kiko Beats with help from contributors.

microlink.io · GitHub microlink.io · Twitter @microlinkhq

1.1.11

7 months ago

1.1.9

8 months ago

1.1.10

8 months ago

1.1.8

12 months ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

3 years ago

1.1.4

5 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago