{"_id":"0cache","_rev":"7-d44a6d5547d52da0ef8607700973288a","name":"0cache","dist-tags":{"latest":"0.0.7"},"versions":{"0.0.1":{"name":"0cache","version":"0.0.1","_id":"0cache@0.0.1","maintainers":[{"name":"yoeven","email":"yoevenkhem@gmail.com"}],"dist":{"shasum":"36febc21838fe677118b07414c9be7aae99f7ac5","tarball":"https://registry.npmjs.org/0cache/-/0cache-0.0.1.tgz","fileCount":5,"integrity":"sha512-SWl7glgQRuWifolN4u17nbegvjexnHcQxoYQmop++yjkvujgRt0TkGJfwhbBwUjke2eoTEtcgJw4WIKs3lYQDA==","signatures":[{"sig":"MEUCIQDYCojNbJHuwfE87G5v1R8Sf2dcvTuZ0QZGBZQZk2qu7wIgEHwaj5sZU6wsQzAJH+lnbiJdJdPFBcmOwrEVlRxRnDU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":104816},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"gitHead":"ec8c386d1be306574775798872185c1d38e3c08e","scripts":{"dev":"bun run example/index.ts","build":"bun run build.ts","format":"biome check --write .","prepublishOnly":"bun run build"},"_npmUser":{"name":"yoeven","email":"yoevenkhem@gmail.com"},"_npmVersion":"10.5.0","description":"Alt cache allows you to cache expensive operations in your code by simply wrapping your function with the `cache` function. This project was inspired by [Vercel's unstable_cache](https://nextjs.org/docs/app/api-reference/functions/unstable_cache) simple s","directories":{},"_nodeVersion":"20.12.2","dependencies":{"pako":"^2.1.0"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest","@types/pako":"^2.0.3","bun-plugin-dts":"^0.3.0"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/0cache_0.0.1_1739866263912_0.8754842104072336","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"0cache","version":"0.0.2","_id":"0cache@0.0.2","maintainers":[{"name":"yoeven","email":"yoevenkhem@gmail.com"}],"dist":{"shasum":"5206c1145b32a55dfed887effbb0dacec513d70c","tarball":"https://registry.npmjs.org/0cache/-/0cache-0.0.2.tgz","fileCount":5,"integrity":"sha512-UqvSnslPIopXNCDNBez57vVpzO42G5tuyhIG/OBl1b5Z5MDs2c63egMZMQ2s4+dmPY4+P6kYZMfXuKAYVi+0Gw==","signatures":[{"sig":"MEQCIH75wyjsFJ0ystHKcntG1dkiJhQ0a/MZ7RmElgCPBWpiAiBpn+n0fOcO9qxv1uk5HxlenBpbySqou3lAFeykP/xKig==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":107630},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"gitHead":"84a52286654237f6f44f6fdc715f01d40d9c3c4f","scripts":{"dev":"bun run example/index.ts","build":"bun run build.ts","format":"biome check --write .","prepublishOnly":"bun run build"},"_npmUser":{"name":"yoeven","email":"yoevenkhem@gmail.com"},"_npmVersion":"10.5.0","description":"Alt cache allows you to cache expensive operations in your code by simply wrapping your function with the `cache` function. This project was inspired by [Vercel's unstable_cache](https://nextjs.org/docs/app/api-reference/functions/unstable_cache) simple s","directories":{},"_nodeVersion":"20.12.2","dependencies":{"pako":"^2.1.0"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest","@types/pako":"^2.0.3","bun-plugin-dts":"^0.3.0"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/0cache_0.0.2_1739974350477_0.41651110032898364","host":"s3://npm-registry-packages-npm-production"}},"0.0.3":{"name":"0cache","version":"0.0.3","keywords":["caching","typescript","javascript","sqlite","nextjs","vercel"],"author":"yoeven","license":"MIT","_id":"0cache@0.0.3","maintainers":[{"name":"yoeven","email":"yoevenkhem@gmail.com"}],"homepage":"https://github.com/yoeven/0cache","bugs":{"url":"https://github.com/yoeven/0cache/issues"},"dist":{"shasum":"073fa08c9b128ce67829588c09893e1ec3a6427d","tarball":"https://registry.npmjs.org/0cache/-/0cache-0.0.3.tgz","fileCount":5,"integrity":"sha512-1w4FOitAii280a94MRN5cQ4xzhZnKgiaUb8i9Dybp5Qx4bMkz+61n8c2juhGPeFYOx9fW0cM6vj6yVNzs04IUw==","signatures":[{"sig":"MEQCIFGJZgyzD58i5LlPDVl5KB6UHdueIwGvdwhajz9+2ZC7AiBy4A713lgPFvBVpB1ULQW053tlRX8ol7B/FpwzcguaHA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":109893},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","shasum":"073fa08c9b128ce67829588c09893e1ec3a6427d","engines":{"node":">=18"},"exports":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"scripts":{"dev":"bun run example/index.ts","build":"bun run build.ts","format":"biome check --write .","prepublishOnly":"bun run build"},"_npmUser":{"name":"yoeven","email":"yoevenkhem@gmail.com"},"_integrity":"sha512-1w4FOitAii280a94MRN5cQ4xzhZnKgiaUb8i9Dybp5Qx4bMkz+61n8c2juhGPeFYOx9fW0cM6vj6yVNzs04IUw==","repository":{"url":"git+https://github.com/yoeven/0cache.git","type":"git"},"_npmVersion":"10.8.3","description":"Cache expensive operations and functions. Inspired by Vercel's unstable_cache","directories":{},"_nodeVersion":"22.6.0","dependencies":{"pako":"^2.1.0"},"_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest","@types/pako":"^2.0.3","bun-plugin-dts":"^0.3.0"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/0cache_0.0.3_1739977226903_0.05115639793873261","host":"s3://npm-registry-packages-npm-production"}},"0.0.4":{"name":"0cache","version":"0.0.4","keywords":["caching","typescript","javascript","postgresql","nextjs","vercel"],"author":{"name":"yoeven"},"license":"MIT","_id":"0cache@0.0.4","maintainers":[{"name":"yoeven","email":"yoevenkhem@gmail.com"}],"homepage":"https://github.com/yoeven/0cache","bugs":{"url":"https://github.com/yoeven/0cache/issues"},"dist":{"shasum":"955b50950342537efc5f3a0d04b269dccf9559f6","tarball":"https://registry.npmjs.org/0cache/-/0cache-0.0.4.tgz","fileCount":8,"integrity":"sha512-oLk8hsvC/l4S7yUhAhtPyJ7u9vHkFAXUFSQDj9V5x+JSxW2K4RVuqZkRkdR0qiad5ThmbQPat3SjuxKnX9sfyQ==","signatures":[{"sig":"MEQCIG6XwAGXilg5gtrFmwnY4jRbkKUpbxDRphFH64lhQSFSAiBQHfldpO03TrlVBrW0sQIkyj0MOoIanPiEP5gl157P9w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/0cache@0.0.4","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":38016},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"gitHead":"07667e31cf72f8bab8bb12441fb74e6010cbe912","scripts":{"dev":"tsx example/index.ts","build":"pkgroll --src=./","format":"prettier --write ."},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f447ddd7-608f-43f7-bd02-3f4ffd95340d"}},"repository":{"url":"git+https://github.com/yoeven/0cache.git","type":"git"},"_npmVersion":"11.11.0","description":"Cache expensive async/sync fetch and functions on any database. Inspired by Vercel's unstable_cache","directories":{},"_nodeVersion":"24.14.1","dependencies":{"pako":"^2.1.0","postgres":"^3.4.9"},"_hasShrinkwrap":false,"packageManager":"yarn@1.22.22","devDependencies":{"tsx":"^4.21.0","pkgroll":"^2.27.0","prettier":"^3.8.1","typescript":"^6.0.2","@types/node":"^25.5.2","@types/pako":"^2.0.3"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/0cache_0.0.4_1775581074357_0.6296173567250418","host":"s3://npm-registry-packages-npm-production"}},"0.0.5":{"name":"0cache","version":"0.0.5","keywords":["caching","typescript","javascript","postgresql","nextjs","vercel"],"author":{"name":"yoeven"},"license":"MIT","_id":"0cache@0.0.5","maintainers":[{"name":"yoeven","email":"yoevenkhem@gmail.com"}],"homepage":"https://github.com/yoeven/0cache","bugs":{"url":"https://github.com/yoeven/0cache/issues"},"dist":{"shasum":"bdec942a306866b6f478a0da85191d14d7c90eaf","tarball":"https://registry.npmjs.org/0cache/-/0cache-0.0.5.tgz","fileCount":8,"integrity":"sha512-7B4qq/+CsWOaN+rYcA9k4//OH840MfUR5BuyqzUiuQ8MjeonfiGNXH4xc6CHe47Q99976fb8XUq87iSfXqOuCQ==","signatures":[{"sig":"MEUCIQCT78WzmQeYhdy5yIfFC6dv4toz2FRMTAQ/J6jwBRCCQAIgJFe7jrAV1h2o9yeYtobxvza4sevbD/8HlOCKpUtB4lU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/0cache@0.0.5","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":39399},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"gitHead":"9bd56a9a11f160df35859ca0f5b9c966e07b5c74","scripts":{"dev":"tsx --env-file=.env example/index.ts","build":"pkgroll --src=./","format":"prettier --write ."},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f447ddd7-608f-43f7-bd02-3f4ffd95340d"}},"repository":{"url":"git+https://github.com/yoeven/0cache.git","type":"git"},"_npmVersion":"11.11.0","description":"Cache expensive async/sync fetch and functions on any database. Inspired by Vercel's unstable_cache","directories":{},"_nodeVersion":"24.14.1","dependencies":{"pako":"^2.1.0","postgres":"^3.4.9"},"_hasShrinkwrap":false,"packageManager":"yarn@1.22.22","devDependencies":{"tsx":"^4.21.0","pkgroll":"^2.27.0","prettier":"^3.8.1","typescript":"^6.0.2","@types/node":"^25.5.2","@types/pako":"^2.0.3"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/0cache_0.0.5_1775606201661_0.9359533391969235","host":"s3://npm-registry-packages-npm-production"}},"0.0.6":{"name":"0cache","version":"0.0.6","keywords":["caching","typescript","javascript","postgresql","nextjs","vercel"],"author":{"name":"yoeven"},"license":"MIT","_id":"0cache@0.0.6","maintainers":[{"name":"yoeven","email":"yoevenkhem@gmail.com"}],"homepage":"https://github.com/yoeven/0cache","bugs":{"url":"https://github.com/yoeven/0cache/issues"},"dist":{"shasum":"d4ebe2221b32f45a5e1a4a3092ff99763a76c0f8","tarball":"https://registry.npmjs.org/0cache/-/0cache-0.0.6.tgz","fileCount":8,"integrity":"sha512-9jQ+l2XK2oO/tyc7wAhXZFG7q+bq5pVPeA2GIy7QfsGpJ58D6ecollyl+rXT2w+xoe/oTS04nf2JL1dvg4kMkA==","signatures":[{"sig":"MEYCIQCANee+Fpn++tl/yQbYSMqWFKG3LkbRYgFZsVMkoMyL+gIhANUYSq2LsIMeJLf2P7Qq4MZNqeZ8y87bmKQ4tsNrKEIs","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/0cache@0.0.6","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":40710},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"gitHead":"25593ca3dd4d447b0e2fa7ff6bc9c17eaffe75a5","scripts":{"dev":"tsx --env-file=.env example/index.ts","build":"pkgroll --src=./","format":"prettier --write ."},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f447ddd7-608f-43f7-bd02-3f4ffd95340d"}},"repository":{"url":"git+https://github.com/yoeven/0cache.git","type":"git"},"_npmVersion":"11.11.0","description":"Cache expensive async/sync fetch and functions on any database. Inspired by Vercel's unstable_cache","directories":{},"_nodeVersion":"24.14.1","dependencies":{"pako":"^2.1.0","postgres":"^3.4.9"},"_hasShrinkwrap":false,"packageManager":"yarn@1.22.22","devDependencies":{"tsx":"^4.21.0","pkgroll":"^2.27.0","prettier":"^3.8.1","typescript":"^6.0.2","@types/node":"^25.5.2","@types/pako":"^2.0.3"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/0cache_0.0.6_1775612629928_0.07552800683986827","host":"s3://npm-registry-packages-npm-production"}},"0.0.7":{"name":"0cache","description":"Cache expensive async/sync fetch and functions on any database. Inspired by Vercel's unstable_cache","homepage":"https://github.com/yoeven/0cache","repository":{"type":"git","url":"git+https://github.com/yoeven/0cache.git"},"bugs":{"url":"https://github.com/yoeven/0cache/issues"},"keywords":["caching","typescript","javascript","postgresql","nextjs","vercel"],"author":{"name":"yoeven"},"license":"MIT","type":"module","version":"0.0.7","packageManager":"yarn@1.22.22","engines":{"node":">=18"},"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"},"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"}},"scripts":{"dev":"tsx --env-file=.env example/index.ts","build":"pkgroll --src=./","format":"prettier --write ."},"devDependencies":{"@types/node":"^25.5.2","@types/pako":"^2.0.3","pkgroll":"^2.27.0","prettier":"^3.8.1","tsx":"^4.21.0","typescript":"^6.0.2"},"peerDependencies":{"typescript":"^5.0.0"},"dependencies":{"pako":"^2.1.0","postgres":"^3.4.9"},"gitHead":"c76882909ca5fb75a9d04df99f3f98e3ad626338","_id":"0cache@0.0.7","_nodeVersion":"24.14.1","_npmVersion":"11.11.0","dist":{"integrity":"sha512-Lh19IcfL6Pbarq4llBryJ/QMaEujFPIhWxdkfN3ZxBFDQWd5HO/6qd8gwZbiiY4zuoqJuD8IVxZ6nKK7KGxyYw==","shasum":"0b3a260aafc23b47e322f78fe69ec4d035131105","tarball":"https://registry.npmjs.org/0cache/-/0cache-0.0.7.tgz","fileCount":8,"unpackedSize":40935,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/0cache@0.0.7","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHnPLtVxRBhvhlf0FNRgukl7kKepV/UZLPnXKtruu+7hAiEA5hVe6iQZiXUL3bbQm9S2WH77px5BZmqpS+fwa4xexxA="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f447ddd7-608f-43f7-bd02-3f4ffd95340d"}},"directories":{},"maintainers":[{"name":"yoeven","email":"yoevenkhem@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/0cache_0.0.7_1775789153149_0.7108510363451774"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-18T08:11:03.911Z","modified":"2026-04-10T02:45:53.592Z","0.0.1":"2025-02-18T08:11:04.178Z","0.0.2":"2025-02-19T14:12:30.656Z","0.0.3":"2025-02-19T15:00:27.071Z","0.0.4":"2026-04-07T16:57:54.493Z","0.0.5":"2026-04-07T23:56:41.795Z","0.0.6":"2026-04-08T01:43:50.064Z","0.0.7":"2026-04-10T02:45:53.298Z"},"bugs":{"url":"https://github.com/yoeven/0cache/issues"},"author":{"name":"yoeven"},"license":"MIT","homepage":"https://github.com/yoeven/0cache","keywords":["caching","typescript","javascript","postgresql","nextjs","vercel"],"repository":{"type":"git","url":"git+https://github.com/yoeven/0cache.git"},"description":"Cache expensive async/sync fetch and functions on any database. Inspired by Vercel's unstable_cache","maintainers":[{"name":"yoeven","email":"yoevenkhem@gmail.com"}],"readme":"# 0cache (Experimental)\n\n0cache allows you to cache expensive async/sync operations in your code by simply wrapping your TS/JS function with the `cache` function.\n\n![architecture](/architecture.png)\n\n- 🔌 Plug and play into any JS/TS project\n- 🎯 Simple wrapper syntax on any function\n- 🕑 Full cache control with tags & TTL\n- 🔄 Manual cache invalidation with tags\n- ∑ Caching of any function, not just async functions\n- ▫︎ Compression for large payloads\n- 🗄️ Bring your own database with adapters (PostgreSQL included)\n- Initially inspired by [Vercel's unstable_cache](https://nextjs.org/docs/app/api-reference/functions/unstable_cache).\n\n## Installation\n\n```bash\nnpm i 0cache\n# or\nyarn add 0cache\n# or\npnpm add 0cache\n# or\nbun add 0cache\n```\n\n## Usage\n\nCreate a cache instance with a **database adapter**. Use `postgresAdapter` with [postgres.js](https://github.com/porsager/postgres) for PostgreSQL.\n\n### Quick start\n\n```ts\nimport { ZeroCache, postgresAdapter, postgres } from \"0cache\";\n\nconst sql = postgres(process.env.DATABASE_URL!);\n\nconst { cache, invalidateByTag } = ZeroCache({\n  dbAdapter: postgresAdapter(sql),\n  debug: true,\n});\n\n// An expensive operation you want to cache\nconst getPDFData = async (url: string) => {\n  const data = await fetch(url);\n  const buffer = await data.arrayBuffer();\n  const base64 = Buffer.from(buffer).toString(\"base64\");\n\n  return { base64, url };\n};\n\n// Wrap with cache — subsequent calls with the same args skip the fetch entirely\nconst getDataCache = cache(getPDFData, {\n  tags: [\"user_1\"],\n});\n\nconst data = await getDataCache(\"https://arxiv.org/pdf/1706.03762\");\nconsole.log(data);\n\n// Invalidate when the underlying data changes\nawait invalidateByTag([\"user_1\"]);\n```\n\nThe `postgresAdapter` expects a `zero_cache` table with `key` as a unique primary key. Example DDL:\n\n```sql\nCREATE TABLE zero_cache (\n  key TEXT PRIMARY KEY,\n  data BYTEA NOT NULL,\n  tags TEXT,\n  ttl BIGINT NOT NULL\n);\n```\n\n`ZeroCache` also returns `invalidateByTag()` and `clearCache()` — use them from the **same** instance you used for `cache`.\n\n### Other options\n\nPass `debug: true` on `ZeroCache` to log cache hits/misses, retrieval times, and result sizes. Can also be set per-cache.\n\n```ts\nconst { cache } = ZeroCache({\n  dbAdapter: postgresAdapter(sql),\n  debug: true,\n  maxSizeMB: 8,\n});\n\nconst getCachedUser = cache(async (id: string) => getUser(id), {\n  revalidate: 60 * 60 * 24,\n  waitUntil: waitUntil,\n  parser: (data: string) => JSON.parse(data),\n  shouldCache: (data: any) => data.length > 100,\n  maxSizeMB: 2,\n});\n```\n\n| Option        | Description                                                                                                                                                                                                                                                                                                                                                                                                              | Type                        | Default           |\n| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------- | ----------------- |\n| `tags`        | Array of string tags to associate with this cache entry for later invalidation. Max 10 tags with a combined 1000 character limit.                                                                                                                                                                                                                                                                                        | `string[]`                  | `[]`              |\n| `revalidate`  | The time to live (TTL) for the cache in seconds, up to 1 month                                                                                                                                                                                                                                                                                                                                                           | `number`                    | `604800` (1 week) |\n| `waitUntil`   | A feature that allows for promises to run in the background even when you have returned a response which is supported on platforms like [Vercel](https://vercel.com/docs/functions/vercel-functions-package#waituntil) & [Cloudflare workers](https://developers.cloudflare.com/workers/runtime-apis/context/#waituntil). Pass a `waitUntil` function and caching processes will use waitUntil to run in the background. | `(p: Promise<any>) => void` | `undefined`       |\n| `parser`      | A custom parser for data retrieved from cache for special formats you would like to handle that is non-json                                                                                                                                                                                                                                                                                                              | `(data: string) => any`     | `undefined`       |\n| `shouldCache` | A custom function that will be called to determine if the data should be cached dynamically based on response.                                                                                                                                                                                                                                                                                                           | `(data: any) => boolean`    | `undefined`       |\n| `maxSizeMB`   | Maximum size in MB of the data to cache. Can also be set globally on `ZeroCache` config.                                                                                                                                                                                                                                                                                                                                 | `number`                    | `4`               |\n| `effects`     | Extra key-value pairs included in the cache key. Useful for differentiating cache entries by external state like user sessions or feature flags.                                                                                                                                                                                                                                                                         | `[string, any][]`           | `undefined`       |\n| `enable`      | Set to `false` to bypass caching entirely and always call the original function.                                                                                                                                                                                                                                                                                                                                         | `boolean`                   | `true`            |\n| `debug`       | Enable debug logging for this specific cache. Overrides the global `debug` setting on `ZeroCache`.                                                                                                                                                                                                                                                                                                                       | `boolean`                   | `false`           |\n\n### Supported return types\n\nOnly JSON-serializable return types are cached. If the function returns an unsupported type, it will still be returned as-is but **not** cached.\n\n| Type     | Cached |\n| -------- | ------ |\n| Object   | ✅     |\n| Array    | ✅     |\n| String   | ✅     |\n| Number   | ✅     |\n| Boolean  | ✅     |\n| `null`   | ❌     |\n| `Map`    | ❌     |\n| `Set`    | ❌     |\n| `Date`   | ❌     |\n| Class    | ❌     |\n| Function | ❌     |\n\n### How tagging & invalidation works\n\n```ts\nconst getCachedOne = cache(async (id: string) => getUser(id), { tags: [\"one\", \"user\"] });\n\nconst getCachedTwo = cache(async (id: string) => getUser(id), { tags: [\"two\", \"user\"] });\n\nconst getCachedThree = cache(async (id: string) => getUser(id), { tags: [\"three\", \"user\"] });\n```\n\nYou can set up to 10 tags, with a total of 1000 characters. Tags are a great way to group cache together allowing you to invalidate them later.\n\nThis would invalidate all cache with the tag `user`. With the above example meaning all three cached data would be invalidated.\n\n```ts\nawait invalidateByTag([\"user\"]);\n```\n\nThis would invalidate cache that has both `user` and `three` tags. With the above example meaning only the third cached data would be invalidated.\n\n```ts\nawait invalidateByTag([\"user\", \"three\"]);\n```\n\n### Cleaning up expired cache\n\n0cache skips expired entries on read and deletes them individually, but expired rows are not automatically purged in bulk. To keep your table lean, set up a scheduled job that deletes rows whose `ttl` is in the past.\n\n**PostgreSQL with pg_cron**\n\n```sql\nSELECT cron.schedule(\n  'purge_expired_cache',\n  '0 * * * *', -- every hour\n  $$DELETE FROM zero_cache WHERE ttl < extract(epoch from now())$$\n);\n```\n\nYou can also handle this with any external cron runner or task scheduler — just run the equivalent `DELETE` query on your chosen interval.\n\n### Custom adapters\n\nYou can create your own adapter by implementing the `DBAdapter` interface:\n\n```ts\nimport type { DBAdapter } from \"0cache\";\n\nconst myAdapter: DBAdapter = {\n  getCacheByKey: async (key) => {\n    /* ... */\n  },\n  deleteCacheByKey: async (key) => {\n    /* ... */\n  },\n  insertCache: async (key, data, tags, ttl) => {\n    /* ... */\n  },\n  deleteCacheByTags: async (tags) => {\n    /* ... */\n  },\n  clearAllCache: async () => {\n    /* ... */\n  },\n};\n\nconst { cache } = ZeroCache({ dbAdapter: myAdapter });\n```\n\n## Why not a Redis database?\n\nRedis is great, but tag-based invalidation gets messy. You either need to scan keys or maintain separate sets to track which keys belong to which tags, that means more round trips and extra bookkeeping just to delete a single group of entries.\n\nWith a relational database like PostgreSQL, tags can be stored as a text column and invalidated with a simple substring match in a single query. One `DELETE` statement with a `LIKE` or pattern check handles what would take multiple commands and bookkeeping in Redis, no extra data structures, no multi-step coordination.\n\nIf tag-based invalidation is core to your caching strategy, a relational database keeps things simpler and more predictable.\n\n## Future\n\n- [ ] Add support for non-json objects such as images etc with compression and s3 storage\n- [ ] Storing larger responses in S3 bucket and mapping the ID to database\n\nI'm open to suggestions and ideas that make caching even simpler, feel free to reach out!\n\n## Inspiration & References:\n\n- https://nextjs.org/docs/app/api-reference/functions/unstable_cache\n- https://github.com/vercel/next.js/blob/8136842ca20ed6801327862f62ee6ec9b3809fac/packages/next/src/server/web/spec-extension/unstable-cache.ts#L342\n- https://github.com/vercel/next.js/blob/8136842ca20ed6801327862f62ee6ec9b3809fac/packages/next/src/server/lib/incremental-cache/index.ts\n","readmeFilename":"README.md"}