{"id":44732,"library":"dirt-simple-file-cache","title":"Dirt Simple File Cache","description":"A lightweight file caching library that uses file modification times (mtime) to determine cache staleness. Current stable version is 0.4.0, released occasionally with minimal maintenance. It provides both persistent file-based caching and optional in-memory caching. Differentiators: dirt-simple API with just init, add, get, and clear methods; uses OS temp directory for persistence; TypeScript typings included. Ideal for simple build tool caches or any scenario where fast, zero-config file caching is needed.","status":"active","version":"0.4.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/thlorenz/dirt-simple-file-cache","tags":["javascript","typescript"],"install":[{"cmd":"npm install dirt-simple-file-cache","lang":"bash","label":"npm"},{"cmd":"yarn add dirt-simple-file-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add dirt-simple-file-cache","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"File system operations for reading/writing cache and checking mtime","package":"fs","optional":true},{"reason":"Path manipulation for cache file paths","package":"path","optional":true}],"imports":[{"note":"Package exports a class; named import required. CJS require would give an object, not the class directly.","wrong":"const DirtSimpleFileCache = require('dirt-simple-file-cache')","symbol":"DirtSimpleFileCache","correct":"import { DirtSimpleFileCache } from 'dirt-simple-file-cache'"},{"note":"For CJS, destructure the class from the exports object. There is no default export.","wrong":"const DirtSimpleFileCache = require('dirt-simple-file-cache').default","symbol":"DirtSimpleFileCache","correct":"const { DirtSimpleFileCache } = require('dirt-simple-file-cache')"},{"note":"Type import is valid for TypeScript, but the class is also a value, so both type and value imports are fine.","wrong":"","symbol":"DirtSimpleFileCache","correct":"import type { DirtSimpleFileCache } from 'dirt-simple-file-cache'"}],"quickstart":{"code":"import path from 'path';\nimport { strict as assert } from 'assert';\nimport { DirtSimpleFileCache } from 'dirt-simple-file-cache';\n\nasync function example() {\n  const cacheDir = '/tmp/my-cache'; // Or use project root\n  const cache = await DirtSimpleFileCache.init(cacheDir);\n  await cache.clear();\n\n  const filePath = path.join(cacheDir, 'test.txt');\n  const data = 'cached content';\n  cache.add(filePath, data);\n\n  const retrieved = cache.get(filePath);\n  assert(retrieved === data);\n\n  const missing = cache.get('/nonexistent');\n  assert(missing == null);\n}\n\nexample().catch(console.error);","lang":"typescript","description":"Initializes a cache instance, adds an entry, retrieves it, and verifies missed cache returns null."},"warnings":[{"fix":"Do not use keepInMemoryCache if source files may change during runtime. For correctness, always use file-based cache.","message":"In-memory cache does not check for staleness; file cache uses mtime but may be slower.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"If you need a custom cache directory, pass a specific root path to init (e.g., projectRoot). The library uses that root directory for caching.","message":"Cache persists to a tmp folder by default, not configurable via init; uses os.tmpdir().","severity":"gotcha","affected_versions":"0.4.0"},{"fix":"Always await cache.clear() in async contexts.","message":"clear() is async; failing to await it may leave stale data.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"N/A","message":"No major deprecations known; library is simple and stable.","severity":"deprecated","affected_versions":"0.4.0"}],"env_vars":null,"search_vec":"'0.4.0':24 'add':52 'api':48 'base':36 'build':69 'cach':4,8,18,37,43,71,81 'clear':55 'config':79 'current':20 'determin':17 'differenti':44 'directori':60 'dirt':1,46 'dirt-simpl':45 'fast':76 'file':3,7,12,35,80 'file-bas':34 'get':53 'ideal':66 'in-memori':40 'includ':65 'init':51 'javascript':84 'librari':9 'lightweight':6 'mainten':29 'memori':42 'method':56 'minim':28 'modif':13 'mtime':15 'need':83 'occasion':26 'option':39 'os':58 'persist':33,62 'provid':31 'releas':25 'scenario':74 'simpl':2,47,68 'stabl':21 'stale':19 'temp':59 'time':14 'tool':70 'type':64 'typescript':63,85 'use':11,57 'version':22 'zero':78 'zero-config':77","created_at":"2026-06-07T12:51:34.105645+00:00","updated_at":"2026-06-07T12:51:34.105645+00:00","problems":[{"fix":"Use const { DirtSimpleFileCache } = require('dirt-simple-file-cache') or import { DirtSimpleFileCache } from 'dirt-simple-file-cache'","cause":"Incorrect import or require; CJS require gave an object without destructuring.","error":"TypeError: DirtSimpleFileCache is not a constructor"},{"fix":"Ensure cache = await DirtSimpleFileCache.init(...) before using get/add/clear.","cause":"Forgetting to await init() or calling get on uninitialized instance.","error":"TypeError: Cannot read properties of undefined (reading 'get')"},{"fix":"Ensure the directory passed to init exists and is writable. The library does not create intermediate directories automatically.","cause":"The cache directory does not exist or permissions issue.","error":"Error: ENOENT: no such file or directory, open '...'"}],"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/thlorenz/dirt-simple-file-cache#readme","github":"ssh://git@github.com/thlorenz/dirt-simple-file-cache","docs":null,"changelog":null,"pypi":null,"npm":"dirt-simple-file-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}}