Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

alleviate

A collection of tiny caching and promise utilities

  • Types
  • ESM
License
MIT
Deps
0
Install Size
29.3 kB
Vulns
Published

Get started

$ npm install alleviatepnpm add alleviateyarn add alleviatebun add alleviatedeno add npm:alleviatevlt install alleviatevp add alleviatenub add alleviateni alleviateupm add alleviate

Weekly DownloadsAcross all versions

Node.js
^22.11 || ^24 || ^26 || ^27
0.2.3
latest

Readme

alleviate

Open on npmx.dev Open on npmx.dev Open on npmx.dev

Usage

  • createLRU - A simple, fast LRU cache.
  • createTTLMap - A more complex promise queue/limiter. Supports more advanced rate limiting than Queue.
  • memoize - Memoize a function, i.e. cache its results based on its parameters to skip re-computation.
  • createQueue - A simple FIFO promise queue.
  • createLimiter - A more complex promise queue/limiter. Supports more advanced rate limiting than Queue.
  • createDataLoader - DataLoader implementation similar to dataloader
LRU

An ever so slightly modified version of flru by lukeed, the fastest and smallest LRU cache I've benchmarked.

Note: It will keep store (and return) the last max * 2 items in memory. When the cache reaches max * 2 + 1 it will evict the current stale entries.

import { createLRU } from "alleviate"

const lru = createLRU({ max: 3 })

lru.set("foo", "bar")
lru.has("foo") // true
lru.get("foo") // "bar", marks "foo" as most recently used
lru.peek("foo") // "bar", does not affect LRU order

lru.setMany({
	biz: "baz",
	lorem: "ipsum",
})
lru.setMany([
	["0", "0"],
	["1", "1"],
	["2", "3"],
])

lru.clear()
TTL Map

A simple TTL Map that evicts entries after a given expiration time.

import { createTTLMap } from "alleviate"

const cache = createTTLMap({ ttl: 60_000 })

cache.set("foo", "bar")
cache.has("foo") // true, does not affect TTL
cache.get("foo") // "bar", refreshes TTL unless `getRefreshesTTL` is false
cache.peek("foo") // "bar", does not affect TTL
cache.clear()
Memoize

Memoize a function, i.e. cache its results based on its parameters to skip re-computation.

import { memoize } from "alleviate"

const fibonacci = memoize((num: number) => {
	/* ... */
})
fibonacci(100)
fibonacci(100) // skips executing function, returns cached result

const memoized = memoize(fn, {
	max: 100, // number of cached results to keep before evicting the oldest
	keepNullish: true, // whether to cache nullish results (null, undefined). Defaults to `false`
	serialize: (params) => {}, // custom parameter serialization for the cache key. Defaults to `fnv1a-64(object-identity(data))`
})
Queue

An intentionally simple promise queue that only accepts a concurrency option.

For more advanced promise limiting (timeouts, pools, etc.), see Limiter.

import { createQueue } from "alleviate"

const queue = createQueue({ concurrency: 4 })

// run a function asap
const response = await queue.run(() => fetch("https://example.com"))

// wrap a function to run it later, or multiple times
const callExample = queue.wrap((path: string) => fetch(`https://example.com/${path}`))
await callExample("foo")
Limiter

Intended as a replacement for bottleneck, p-queue.

import { createLimiter } from "alleviate"

const limiter = createLimiter({
	concurrency: 4, // How many promises can be running at once (defaults to 3/4ths of available threads)
	pool: 4, // Max number of calls before blocking (defaults to `concurrency`)
	initial: 16, // How much the pool starts with (defaults to `pool`)
	refill: 60, // How much the pool increases per `refillInterval` (defaults to `pool`)
	refillInterval: 1000, // How often the pool is refilled in ms
	refillOverLimit: false, // Whether the pool should be refilled over its limit
	timeout: null, // How long to wait in ms for a call to resolve before rejecting
})

const response = await limiter.run(() => fetch("https://example.com"))

const callExample = limiter.wrap((path: string) => fetch(`https://example.com/${path}`))
await callExample("foo")

// If `timeout` is set, `.run()` will receive an AbortSignal.
const limiter = createLimiter({ timeout: 100 })
const response = await limiter.run((signal) => fetch("https://example.com", { signal }))

/* -- Examples -- */

// 60 requests per minute
const limiter = createLimiter({
	concurrency: 16,
	pool: 60,
	refillInterval: 60_000,
})

// 60 requests per minute, more spread out
const limiter = createLimiter({
	concurrency: 16,
	pool: 60,
	initial: 16,
	refill: 10,
	refillInterval: 10_000,
})
Comparisons

updated 2026-06-22

library install size bundle size external sync (e.g. redis) reservoir-style limiting
alleviate 22kB 1.1kB ❌ ✅
p-queue 171kB (+777%) 12kB (+1091%) ❌ ❌
bottleneck 629kB (+2859%) 61kb (+5545%) ✅ ✅
DataLoader

Easily batch and cache async function calls (e.g. requests).

const dataloader = createDataLoader<string, number>({
	// The loader function receives a batch of keys passed into `load` and `loadMany`
	// and must returns an array where the items must match the order of the keys.
	loader: async (keys: string[]): Promise<number[]> => {
		const result = await fetchData(keys)
		return keys.map((key) => result[key])
	},
	// Whether to cache results. Also accepts `Map`s.
	cache: true,
	// Allows customizing how the keys are serialized for caching. Defaults to `object-identity`.
	cacheKeyFn: (key): string => key,
	// Whether to cache errors *returned* by the loader (not the loader throwing)
	cacheErrors: true,
	// Whether to limit batch sizes and by how much. Defaults to no max batch size.
	maxBatchSize: 25,
})