{"name":"@eggjs/koa-static-cache","version":"6.1.0","keywords":["koa","middleware","file","static","cache","gzip","sendfile"],"license":"MIT","_id":"@eggjs/koa-static-cache@6.1.0","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":"dead_horse","email":"dead_horse@qq.com"},{"name":"wanghx","email":"whxaxes@gmail.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"mansonchor.zzw","email":"mansonchor1987@gmail.com"},{"name":"hubcarl","email":"hubcarl@126.com"},{"name":"gemwuu","email":"gemwuu@gmail.com"},{"name":"akitasummer","email":"644171127@qq.com"}],"homepage":"https://github.com/eggjs/koa-static-cache#readme","bugs":{"url":"https://github.com/eggjs/koa-static-cache/issues"},"dist":{"shasum":"9d39240b422c9922838beb5965f89366750fa403","tarball":"http://registry-npm.ywwl.com/@eggjs/koa-static-cache/download/@eggjs/koa-static-cache-6.1.0.tgz","fileCount":11,"integrity":"sha512-RQ0I8rtucU0vNk58NJizabqqBmj8wJAPFhFPQozu7ldNhjoyWGchak4fLTIt9+nTjlwMogBr9cFWQaaHA3jFxw==","signatures":[{"sig":"MEUCIQCkAys3hwfjJUtKdRhZWcXaSlZlpQThSbR2Nr/LFflKCgIgUbNGiTtLa7dy/RVmQ6dRAUkLj91yP0fdUYZqhHDCIiE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fkoa-static-cache@6.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":60922,"size":13429,"noattachment":false,"key":"/@eggjs/koa-static-cache/-/@eggjs/koa-static-cache-6.1.0.tgz"},"main":"./dist/commonjs/index.js","tshy":{"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":">= 18.19.0"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json"},"gitHead":"cc57f8611d972fbdd4aa267cb1c1cc85783c37f5","scripts":{"ci":"egg-bin cov","lint":"eslint --cache src test --ext .ts","test":"egg-bin test","clean":"rimraf dist","preci":"npm run clean &&  npm run lint","postci":"npm run prepublishOnly && npm run clean","pretest":"npm run clean && npm run lint -- --fix","prepublishOnly":"tshy && tshy-after && attw --pack"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"repository":{"url":"git+https://github.com/eggjs/koa-static-cache.git","type":"git"},"_npmVersion":"10.8.2","description":"Static cache middleware for koa","directories":{},"_nodeVersion":"20.18.3","dependencies":{"utility":"^2.4.0","mime-types":"^2.1.35","@eggjs/compressible":"^3.0.0","fs-readdir-recursive":"^1.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tshy":"3","ylru":"2","eslint":"8","rimraf":"6","@eggjs/bin":"7","@eggjs/koa":"2","tshy-after":"1","typescript":"5","@types/node":"22","@types/mocha":"10","@eggjs/tsconfig":"1","@eggjs/supertest":"8","@types/mime-types":"^2.1.4","eslint-config-egg":"14","@arethetypeswrong/cli":"^0.17.4","@types/fs-readdir-recursive":"^1.1.3"},"_npmOperationalInternal":{"tmp":"tmp/koa-static-cache_6.1.0_1741795069089_0.14526671838675687","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":1741795069288,"_cnpm_publish_time":1741795069288,"dist-tags":{"beta":"7.0.2-beta.27","latest":"7.1.0","rc":"7.0.2-rc.1"}}