{"id":44681,"library":"dataloader-cache-lru","title":"dataloader-cache-lru","description":"An LRU (least recently used) cache implementation compatible with Facebook's DataLoader. Version 1.0.1 is the current stable release; the package has not seen updates since 2017, reflecting a maintenance or deprecated state. It wraps the lru-cache module to provide bounded memory usage for DataLoader instances that persist across requests, such as in GraphQL contexts. Unlike the default Map cache, it evicts least recently used entries when the cache size limit is exceeded. Also supports clearing specific keys when records mutate. This package is specific to DataLoader and offers no alternative caching strategies.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"git://github.com/eddyystop/dataloader-cache-lru","tags":["javascript","feathers","feathers-plus","feathers-plugin","dataloader","DataLoader","GraphQL","cache","LRU"],"install":[{"cmd":"npm install dataloader-cache-lru","lang":"bash","label":"npm"},{"cmd":"yarn add dataloader-cache-lru","lang":"bash","label":"yarn"},{"cmd":"pnpm add dataloader-cache-lru","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Underlying LRU cache implementation","package":"lru-cache","optional":false}],"imports":[{"note":"The module exports a single function as default. Named export is incorrect.","wrong":"import { createCache } from 'dataloader-cache-lru';","symbol":"default (function)","correct":"import createCache from 'dataloader-cache-lru';"},{"note":"CommonJS require returns the function directly; destructuring is wrong.","wrong":"const { createCache } = require('dataloader-cache-lru');","symbol":"default (require)","correct":"const createCache = require('dataloader-cache-lru');"},{"note":"TypeScript users should use default import; namespace import is not needed and may cause type issues.","wrong":"import * as createCache from 'dataloader-cache-lru';","symbol":"TypeScript","correct":"import createCache from 'dataloader-cache-lru';"}],"quickstart":{"code":"const DataLoader = require('dataloader');\nconst createCache = require('dataloader-cache-lru');\n\nconst cacheMap = createCache({ max: 3 });\nconst batchLoadFn = (keys) => Promise.all(keys.map(k => ({ key: k, data: k })));\nconst loader = new DataLoader(batchLoadFn, { cacheMap });\n\nloader.load('a').then(console.log);\nconsole.log(cacheMap.keys().sort()); // ['a']\nloader.clear('a');\nconsole.log(cacheMap.keys().sort()); // []","lang":"javascript","description":"Shows creation of an LRU cache with max size 3, using it with DataLoader, loading a key, and clearing it."},"warnings":[{"fix":"Use @types/dataloader-cache-lru if available, or declare module manually.","message":"The package has no TypeScript definitions.","severity":"breaking","affected_versions":"*"},{"fix":"Consider alternatives like @keyv/lru or manual LRU using lru-cache directly.","message":"Package not updated since 2017; lru-cache versions may have breaking changes.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"If using custom cache, ensure it implements the CacheMap interface.","message":"The cache object's methods (set, get, delete, clear, keys) must match DataLoader's expected interface.","severity":"gotcha","affected_versions":"*"},{"fix":"Refer to lru-cache documentation for options like max, maxAge, etc.","message":"Options passed to createCache are passed directly to lru-cache constructor.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'1.0.1':18 '2017':31 'across':55 'also':80 'altern':97 'bound':47 'cach':3,10,43,66,75,98,111 'clear':82 'compat':12 'context':61 'current':21 'dataload':2,16,51,93,108,109 'dataloader-cache-lru':1 'default':64 'deprec':36 'entri':72 'evict':68 'exceed':79 'facebook':14 'feather':101,103,106 'feathers-plugin':105 'feathers-plus':102 'graphql':60,110 'implement':11 'instanc':52 'javascript':100 'key':84 'least':7,69 'limit':77 'lru':4,6,42,112 'lru-cach':41 'mainten':34 'map':65 'memori':48 'modul':44 'mutat':87 'offer':95 'packag':25,89 'persist':54 'plugin':107 'plus':104 'provid':46 'recent':8,70 'record':86 'reflect':32 'releas':23 'request':56 'seen':28 'sinc':30 'size':76 'specif':83,91 'stabl':22 'state':37 'strategi':99 'support':81 'unlik':62 'updat':29 'usag':49 'use':9,71 'version':17 'wrap':39","created_at":"2026-06-07T12:51:19.392114+00:00","updated_at":"2026-06-07T12:51:19.392114+00:00","problems":[{"fix":"Use `const createCache = require('dataloader-cache-lru');` or `import createCache from 'dataloader-cache-lru';`","cause":"Importing a named export instead of default","error":"TypeError: createCache is not a function"},{"fix":"Call createCache: `const cacheMap = createCache({ max: 100 });`","cause":"Passing result of createCache without calling it as a function","error":"DataLoader requires a valid cache map (cacheMap must have a function 'get')"},{"fix":"Run `npm install lru-cache` as this package depends on it.","cause":"Missing peer dependency lru-cache","error":"Cannot find module 'lru-cache'"},{"fix":"Use the cache object returned by createCache, which implements delete.","cause":"Using a plain Map() or object that doesn't implement delete","error":"The provided cache does not support 'delete' method. DataLoader requires delete."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/eddyystop/dataloader-cache-lru","github":"git://github.com/eddyystop/dataloader-cache-lru","docs":null,"changelog":null,"pypi":null,"npm":"dataloader-cache-lru","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}