A fast, lightweight cache and batching library for single-user GraphQL requests, inspired by DataLoader. Version 2.1.0 is stable, MIT-licensed, and ships TypeScript types. It creates per-request cache instances that batch multiple calls to the same loader into a single async function invocation. Benchmarks show it is 3x faster than DataLoader. Supports object keys via safe-stable-stringify, configurable caching and batch sizes. Published to npm, actively maintained by mcollina.
npm install single-user-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a factory, adds a loader, creates a per-request cache, and batches two calls.
Always call factory.create(newContext) for each new request context.
Set cache: true to enable caching, or handle deduplication manually.
No action needed unless you rely on property order for uniqueness; then use a primitive key.
Leave maxBatchSize undefined for full batching, or set to a positive integer to limit batch size.
Ensure you import Factory correctly: import { Factory } from 'single-user-cache' or const { Factory } = require('single-user-cache').Install the missing dependency: npm install safe-stable-stringify
Pass a plain object as context: factory.create({ requestId: 'abc' })