{"id":45512,"library":"nano-cache","title":"nano-cache","description":"nano-cache is a lightweight in-memory cache for Node.js (version 1.1.2, last updated 2018). It provides TTL, access-limit, and memory-limit based expiration with LRU eviction, compressed storage for higher capacity, and event emitters for cache operations. Unlike larger caches like node-cache or lru-cache, it focuses on simplicity and supports per-item TTL/limit overrides. It requires JSON-serializable values and emits events on get/set/del/clear. No breaking changes have been reported, but the package is in maintenance mode.","status":"maintenance","version":"1.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/akhoury/nano-cache","tags":["javascript"],"install":[{"cmd":"npm install nano-cache","lang":"bash","label":"npm"},{"cmd":"yarn add nano-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add nano-cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package uses CommonJS and exports a singleton by default. No ESM export available.","wrong":"import cache from 'nano-cache';","symbol":"default singleton","correct":"const cache = require('nano-cache');"},{"note":"The constructor is the default export; destructuring results in undefined.","wrong":"const { NanoCache } = require('nano-cache');","symbol":"NanoCache constructor","correct":"const NanoCache = require('nano-cache');\nconst cache = new NanoCache();"},{"note":"SIZE is a static property on the constructor, not a separate export.","wrong":"const { SIZE } = require('nano-cache');","symbol":"NanoCache.SIZE constants","correct":"const NanoCache = require('nano-cache');\nconst bytes = 100 * NanoCache.SIZE.MB;"}],"quickstart":{"code":"const NanoCache = require('nano-cache');\nconst cache = new NanoCache({ ttl: 60000, bytes: 10 * NanoCache.SIZE.MB });\ncache.on('set', (key) => console.log(`Set: ${key}`));\ncache.set('user', { id: 1, name: 'Alice' });\nconst user = cache.get('user');\nconsole.log(user); // { id: 1, name: 'Alice' }\nconsole.log('Stats:', cache.stats());","lang":"javascript","description":"Creates a cache with a 60-second TTL and 10 MB memory limit, sets a key, retrieves it, and logs stats."},"warnings":[{"fix":"Ensure values are plain objects, strings, numbers, booleans, null, or arrays thereof.","message":"Values must be JSON-serializable; objects with functions, undefined, or circular references will break.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `new NanoCache()` for isolated cache instances instead of the singleton.","message":"The default singleton is easily shared across modules; accidental cross-contamination can occur.","severity":"gotcha","affected_versions":"all"},{"fix":"Call `cache.removeAllListeners()` or use scoped listeners with `cache.off()`.","message":"Event listeners must be removed manually to avoid memory leaks; package does not auto-clean.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider migrating to actively maintained alternatives like lru-cache or node-cache.","message":"Package is in maintenance mode; no updates since 2018.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.1.2':17 '2018':20 'access':25 'access-limit':24 'base':31 'break':81 'cach':3,6,13,45,49,53,57 'capac':40 'chang':82 'compress':36 'emit':76 'emitt':43 'event':42,77 'evict':35 'expir':32 'focus':59 'get/set/del/clear':79 'higher':39 'in-memori':10 'item':66 'javascript':93 'json':72 'json-serializ':71 'larger':48 'last':18 'lightweight':9 'like':50 'limit':26,30 'lru':34,56 'lru-cach':55 'mainten':91 'memori':12,29 'memory-limit':28 'mode':92 'nano':2,5 'nano-cach':1,4 'node':52 'node-cach':51 'node.js':15 'oper':46 'overrid':68 'packag':88 'per':65 'per-item':64 'provid':22 'report':85 'requir':70 'serializ':73 'simplic':61 'storag':37 'support':63 'ttl':23 'ttl/limit':67 'unlik':47 'updat':19 'valu':74 'version':16","created_at":"2026-06-07T12:55:22.891570+00:00","updated_at":"2026-06-07T12:55:22.891570+00:00","problems":[{"fix":"Use `const cache = require('nano-cache'); cache.get('key');`","cause":"Using the singleton incorrectly (e.g., calling `NanoCache.get()` but importing wrong).","error":"TypeError: cache.get is not a function"},{"fix":"Reduce the `bytes` value or use `NanoCache.SIZE.MB` to stay within limits.","cause":"Setting `bytes` option to a value larger than available memory.","error":"RangeError: bytes exceeds maximum allowed"},{"fix":"Add `const NanoCache = require('nano-cache');` at the top of the file.","cause":"Attempting to use `NanoCache.SIZE` without requiring the module.","error":"ReferenceError: NanoCache is not defined"}],"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/akhoury/nano-cache#readme","github":"https://github.com/akhoury/nano-cache","docs":null,"changelog":null,"pypi":null,"npm":"nano-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"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}}