{"id":44851,"library":"etag-cache-leveldb","title":"etag-cache-leveldb","description":"A persistent HTTP ETag cache backed by LevelDB for Node.js. Current stable version is 2.1.17. It uses levelup and leveldown (or any abstract-leveldown-compatible store) to persist ETags and response bodies, enabling conditional requests (If-None-Match) and caching of fetch responses. It reconstructs Response-like objects when a cached entry matches. Key differentiators: direct integration with fetch API responses, simple key-value design (URL→ETag and ETag→body), and support for custom LevelDB instances. Release cadence is irregular as a side project.","status":"active","version":"2.1.17","language":"javascript","source_language":"en","source_url":"https://github.com/arlac77/etag-cache-leveldb","tags":["javascript","cache","etag","fetch","http","leveldb","typescript"],"install":[{"cmd":"npm install etag-cache-leveldb","lang":"bash","label":"npm"},{"cmd":"yarn add etag-cache-leveldb","lang":"bash","label":"yarn"},{"cmd":"pnpm add etag-cache-leveldb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for LevelDB interface","package":"levelup","optional":false},{"reason":"Default LevelDB backend (can be replaced with other abstract-leveldown-compatible stores)","package":"leveldown","optional":true}],"imports":[{"note":"Package exports ES module. Use named import.","wrong":"const ETagCacheLevelDB = require('etag-cache-leveldb');","symbol":"ETagCacheLevelDB","correct":"import { ETagCacheLevelDB } from 'etag-cache-leveldb'"},{"note":"Dynamic import works as well.","symbol":"ETagCacheLevelDB","correct":"const { ETagCacheLevelDB } = await import('etag-cache-leveldb')"},{"note":"Type import for TypeScript when only using types.","symbol":"ETagCacheLevelDB","correct":"import type { ETagCacheLevelDB } from 'etag-cache-leveldb'"},{"note":"rawTagData is a helper function for internal use but exported.","wrong":"const rawTagData = require('etag-cache-leveldb').rawTagData;","symbol":"rawTagData","correct":"import { rawTagData } from 'etag-cache-leveldb'"}],"quickstart":{"code":"import levelup from 'levelup';\nimport leveldown from 'leveldown';\nimport { ETagCacheLevelDB } from 'etag-cache-leveldb';\n\nconst db = await levelup(leveldown('./leveldb-cache'));\nconst cache = new ETagCacheLevelDB(db);\n\nconst url = 'https://api.example.com/data';\nconst response = await fetch(url);\nawait cache.storeResponse(response);\n\nconst headers = {};\nconst etagFound = await cache.addHeaders(url, headers);\nif (etagFound) {\n  const conditionalResponse = await fetch(url, { headers });\n  if (conditionalResponse.status === 304) {\n    const cachedResponse = await cache.loadResponse(conditionalResponse);\n    const body = await cachedResponse.text();\n    console.log('Cached body:', body);\n  }\n}","lang":"typescript","description":"Demonstrates creating a LevelDB-backed ETag cache, storing a response, adding conditional headers, and loading a cached response on 304."},"warnings":[{"fix":"Clone the response before storing if you intend to read its body elsewhere: response.clone()","message":"storeResponse() expects a Response object; passing a fetch Response with a non-cloned body may consume the stream.","severity":"gotcha","affected_versions":"all"},{"fix":"Pass a mutable headers object (e.g., new Headers() or a plain object).","message":"addHeaders() modifies the headers object in place.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure you create a separate LevelDB instance per cache instance.","message":"The LevelDB backend must be provided via levelup; the package does not support sublevel or multiple databases without manual setup.","severity":"deprecated","affected_versions":"all"},{"fix":"Always call levelup(leveldown(path)) before passing to ETagCacheLevelDB.","message":"The constructor expects a prepared levelup instance; passing a raw levelup factory or leveldown instance will fail.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Check response status 304 or use addHeaders() first. Ensure response.headers.get('ETag') is present.","message":"loadResponse() only works if the response has an ETag header and the ETag matches a stored body; otherwise it throws.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'2.1.17':19 'abstract':28 'abstract-leveldown-compat':27 'api':67 'back':10 'bodi':37,78 'cach':3,9,46,58,94 'cadenc':86 'compat':30 'condit':39 'current':15 'custom':82 'design':73 'differenti':62 'direct':63 'enabl':38 'entri':59 'etag':2,8,34,75,77,95 'etag-cache-leveldb':1 'fetch':48,66,96 'http':7,97 'if-none-match':41 'instanc':84 'integr':64 'irregular':88 'javascript':93 'key':61,71 'key-valu':70 'leveldb':4,12,83,98 'leveldown':24,29 'levelup':22 'like':54 'match':44,60 'node.js':14 'none':43 'object':55 'persist':6,33 'project':92 'reconstruct':51 'releas':85 'request':40 'respons':36,49,53,68 'response-lik':52 'side':91 'simpl':69 'stabl':16 'store':31 'support':80 'typescript':99 'url':74 'use':21 'valu':72 'version':17","created_at":"2026-06-07T12:52:09.097801+00:00","updated_at":"2026-06-07T12:52:09.097801+00:00","problems":[{"fix":"const db = levelup(leveldown('/path'));","cause":"Passing a raw leveldown instance instead of a levelup instance","error":"TypeError: db.put is not a function"},{"fix":"Check that the response has an ETag header and that storeResponse() was called earlier for the same URL.","cause":"Calling loadResponse() on a response that doesn't have a matching ETag or was not stored","error":"Error: ETag not found in cache"},{"fix":"Ensure headers parameter is an object (e.g., new Headers() or {}).","cause":"Passing undefined or null to addHeaders instead of a headers object","error":"TypeError: Cannot read properties of undefined (reading 'headers')"}],"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/arlac77/etag-cache-leveldb#readme","github":"https://github.com/arlac77/etag-cache-leveldb","docs":null,"changelog":null,"pypi":null,"npm":"etag-cache-leveldb","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}}