{"name":"@eggjs/koa-static-cache","version":"7.0.0-beta.21","keywords":["koa","middleware","file","static","cache","gzip","sendfile"],"license":"MIT","_id":"@eggjs/koa-static-cache@7.0.0-beta.21","maintainers":[{"name":"gxkl","email":"gxkl203@gmail.com"},{"name":"eggjs-admin","email":"fengmk2+eggjs@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"atian25","email":"atian25@qq.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"akitasummer","email":"akitasummer@outlook.com"}],"homepage":"https://github.com/eggjs/egg/tree/next/packages/koa-static-cache","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"0de4e4a7d157f8d9c3b2f9b03a698daedea04da1","tarball":"http://registry-npm.ywwl.com/@eggjs/koa-static-cache/download/@eggjs/koa-static-cache-7.0.0-beta.21.tgz","fileCount":5,"integrity":"sha512-vwCCvsJrMoNEsGjgosJeO1TkdBR/APGdV9+RT6MfhZsb3IGycd/AY9K+1YT96iqaYQeRrBFSrir3sg7G6YEDAw==","signatures":[{"sig":"MEUCIQDt9t/pjA7BOXdV997jlYv0KobNdysma+pk6LU/RrsYfAIgZn8efuEIWFUWjVDVk5k5aQTahj0rhNMOYHgl0Kae1KE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fkoa-static-cache@7.0.0-beta.21","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":29935,"size":8992,"noattachment":false,"key":"/@eggjs/koa-static-cache/-/@eggjs/koa-static-cache-7.0.0-beta.21.tgz"},"main":"./dist/index.js","type":"module","_from":"file:eggjs-koa-static-cache-7.0.0-beta.21.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=22.18.0"},"exports":{".":"./dist/index.js","./package.json":"./package.json"},"scripts":{"ci":"vitest run --coverage","lint":"oxlint --type-aware","test":"npm run lint:fix && vitest run","build":"tsdown && rimraf dist && tsc -b --clean && tsc","lint:fix":"npm run lint -- --fix","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:339a8850-ed43-4758-b433-29e3725832a6"}},"_resolved":"/tmp/66c17f2591865f8bfca12efa9805a5d6/eggjs-koa-static-cache-7.0.0-beta.21.tgz","_integrity":"sha512-vwCCvsJrMoNEsGjgosJeO1TkdBR/APGdV9+RT6MfhZsb3IGycd/AY9K+1YT96iqaYQeRrBFSrir3sg7G6YEDAw==","repository":{"url":"git://github.com/eggjs/egg.git","type":"git","directory":"packages/koa-static-cache"},"_npmVersion":"11.6.1","description":"Static cache middleware for koa","directories":{},"_nodeVersion":"22.20.0","dependencies":{"utility":"^2.5.0","mime-types":"^3.0.0","@eggjs/compressible":"^3.0.0","fs-readdir-recursive":"^1.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"ylru":"^2.0.0","oxlint":"^1.19.0","rimraf":"^6.0.1","tsdown":"^0.15.4","vitest":"4.0.0-beta.16","@eggjs/bin":"8.0.0-beta.21","@eggjs/koa":"3.1.0-beta.21","typescript":"^5.9.3","@types/node":"^24.6.2","@eggjs/tsconfig":"3.1.0-beta.21","oxlint-tsgolint":"^0.2.0","@eggjs/supertest":"9.0.0-beta.21","@types/mime-types":"^3.0.0","@types/fs-readdir-recursive":"^1.1.3"},"_npmOperationalInternal":{"tmp":"tmp/koa-static-cache_7.0.0-beta.21_1759597870673_0.8456103408265299","host":"s3://npm-registry-packages-npm-production"},"readme":"# eggjs/koa-static-cache\n\n[![NPM version][npm-image]][npm-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/@eggjs/koa-static-cache.svg?style=flat)](https://nodejs.org/en/download/)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)\n\n[npm-image]: https://img.shields.io/npm/v/@eggjs/koa-static-cache.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@eggjs/koa-static-cache\n[snyk-image]: https://snyk.io/test/npm/@eggjs/koa-static-cache/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/@eggjs/koa-static-cache\n[download-image]: https://img.shields.io/npm/dm/@eggjs/koa-static-cache.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@eggjs/koa-static-cache\n\nStatic cache middleware for koa.\n\nDifferences between this library and other libraries such as [static](https://github.com/koajs/static):\n\n- There is no directory or `index.html` support.\n- You may optionally store the data in memory - it streams by default.\n- Caches the assets on initialization - you need to restart the process to update the assets.(can turn off with options.preload = false)\n- Uses MD5 hash sum as an ETag.\n- Uses `.gz` files if present on disk, like nginx gzip_static module\n\n> Forked from https://github.com/koajs/static-cache, refactor with TypeScript to support CommonJS and ESM both.\n\n## Installation\n\n```bash\nnpm install @eggjs/koa-static-cache\n```\n\n## API\n\n### staticCache([options])\n\n```js\nconst path = require('path');\nconst { staticCache } = require('@eggjs/koa-static-cache');\n\napp.use(\n  staticCache(path.join(__dirname, 'public'), {\n    maxAge: 365 * 24 * 60 * 60,\n  }),\n);\n```\n\n- `options.dir` (str) - the directory you wish to serve, default to `process.cwd`.\n- `options.maxAge` (int) - cache control max age for the files, `0` by default.\n- `options.cacheControl` (str) - optional cache control header. Overrides `options.maxAge`.\n- `options.buffer` (bool) - store the files in memory instead of streaming from the filesystem on each request.\n- `options.gzip` (bool) - when request's accept-encoding include gzip, files will compressed by gzip.\n- `options.usePrecompiledGzip` (bool) - try use gzip files, loaded from disk, like nginx gzip_static\n- `options.alias` (obj) - object map of aliases. See below.\n- `options.prefix` (str) - the url prefix you wish to add, default to `''`.\n- `options.dynamic` (bool) - dynamic load file which not cached on initialization.\n- `options.filter` (function | array) - filter files at init dir, for example - skip non build (source) files. If array set - allow only listed files\n- `options.preload` (bool) - caches the assets on initialization or not, default to `true`. always work together with `options.dynamic`.\n- `options.files` (obj) - optional files object. See below.\n\n### Aliases\n\nFor example, if you have this `alias` object:\n\n```js\nconst options = {\n  alias: {\n    '/favicon.png': '/favicon-32.png',\n  },\n};\n```\n\nThen requests to `/favicon.png` will actually return `/favicon-32.png` without redirects or anything.\nThis is particularly important when serving [favicons](https://github.com/audreyr/favicon-cheat-sheet) as you don't want to store duplicate images.\n\n### Files\n\nYou can pass in an optional files object.\nThis allows you to do two things:\n\n#### Combining directories into a single middleware\n\nInstead of doing:\n\n```js\napp.use(staticCache('/public/js'));\napp.use(staticCache('/public/css'));\n```\n\nYou can do this:\n\n```js\nconst files = {};\n\n// Mount the middleware\napp.use(staticCache('/public/js', {}, files));\n\n// Add additional files\nstaticCache('/public/css', {}, files);\n```\n\nThe benefit is that you'll have one less function added to the stack as well as doing one hash lookup instead of two.\n\n#### Editing the files object\n\nFor example, if you want to change the max age of `/package.json`, you can do the following:\n\n```js\nconst files = {};\n\napp.use(\n  staticCache(\n    '/public',\n    {\n      maxAge: 60 * 60 * 24 * 365,\n    },\n    files,\n  ),\n);\n\nfiles['/package.json'].maxAge = 60 * 60 * 24 * 30;\n```\n\n#### Using a LRU cache to avoid OOM when dynamic mode enabled\n\nYou can pass in a lru cache instance which has tow methods: `get(key)` and `set(key, value)`.\n\n```js\nconst LRU = require('lru-cache');\nconst files = new LRU({ max: 1000 });\n\napp.use(\n  staticCache({\n    dir: '/public',\n    dynamic: true,\n    files,\n  }),\n);\n```\n\n## License\n\n[MIT](LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1759597870856,"_cnpm_publish_time":1759597870856,"dist-tags":{"beta":"7.0.2-beta.27","latest":"7.1.0","rc":"7.0.2-rc.1"}}