{"id":13779904,"url":"https://github.com/koajs/s3-cache","last_synced_at":"2025-10-19T13:31:36.714Z","repository":{"id":29888781,"uuid":"33434226","full_name":"koajs/s3-cache","owner":"koajs","description":"Koa middleware to cache and serve from S3","archived":false,"fork":false,"pushed_at":"2021-06-28T01:47:55.000Z","size":11,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-29T15:32:15.746Z","etag":null,"topics":["cache","koa","koajs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koajs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-05T07:48:03.000Z","updated_at":"2024-07-19T23:58:04.000Z","dependencies_parsed_at":"2022-08-23T04:50:30.506Z","dependency_job_id":null,"html_url":"https://github.com/koajs/s3-cache","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fs3-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fs3-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fs3-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fs3-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/s3-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237133604,"owners_count":19260508,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","koa","koajs"],"created_at":"2024-08-03T18:01:10.381Z","updated_at":"2025-10-19T13:31:36.707Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","funding_links":[],"categories":["Middleware"],"sub_categories":[],"readme":"\n# s3-cache\n\n[![NPM version][npm-image]][npm-url]\n[![Build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![Dependency Status][david-image]][david-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n\n\u003e NOTE: MAINTAINER WANTED\n\nCaches and serves responses to and from S3.\nSimilar to [koa-cash](https://github.com/koajs/cash),\nexcept it optimizes for the S3 use-case by streaming.\n\nUsage:\n\n```js\nlet cache = require('koa-s3-cache')({\n  // s3 credentials and stuff\n})\n\napp.use(function* (next) {\n  // served from cache\n  if (yield* cache.get(this)) return\n\n  // do some crazy computation\n  this.body = new Buffer(1024 * 1024)\n\n  // save it to s3\n  yield* cache.put(this)\n})\n```\n\nThis is best for dynamically created content that is cached (i.e. thumbnails).\nInstead of caching yourself in the business logic,\ncache transparently with this module.\n\n## API\n\n### const cache = Cache(options)\n\nCreate a `cache` instance.\n\nS3 options:\n\n- `key`\n- `secret`\n- `bucket`\n\nOther options:\n\n- `salt` - add a salt to namespace your `cache` instances\n\n### app.use(cache)\n\nYou can use the cache as middleware,\nwhich caches all downstream middleware.\n\n```js\napp.use(cache)\n\napp.use(function* () {\n  this.body = 'something computationally intensive'\n})\n```\n\n### app.use(cache.wrap( next =\u003e ))\n\nWrap a middleware with the cache.\nUseful for conditional caching\n\n```js\napp.use(cache.wrap(function* () {\n  this.body = 'something computationally intensive'\n}))\n```\n\n### const served = yield cache.get(this)\n\nServe this request from the cache.\nReturns `served`, which is whether the response has been served from the cache.\n\n### yield cache.put(this)\n\nCaches the current response.\n\n## Notes\n\n- You should set an object lifecycle rule.\n  Ex. delete all files in the bucket after 7 days.\n- Objects are stored with `REDUCED_REDUNDANCY`.\n- Only supports `200-2` status codes.\n- If the body is streaming, the stream is cached to the filesystem so that the S3 client knows its `content-length`.\n\n[npm-image]: https://img.shields.io/npm/v/koa-s3-cache.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-s3-cache\n[github-tag]: http://img.shields.io/github/tag/koajs/s3-cache.svg?style=flat-square\n[github-url]: https://github.com/koajs/s3-cache/tags\n[travis-image]: https://img.shields.io/travis/koajs/s3-cache.svg?style=flat-square\n[travis-url]: https://travis-ci.org/koajs/s3-cache\n[coveralls-image]: https://img.shields.io/coveralls/koajs/s3-cache.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/koajs/s3-cache\n[david-image]: http://img.shields.io/david/koajs/s3-cache.svg?style=flat-square\n[david-url]: https://david-dm.org/koajs/s3-cache\n[license-image]: http://img.shields.io/npm/l/koa-s3-cache.svg?style=flat-square\n[license-url]: LICENSE\n[downloads-image]: http://img.shields.io/npm/dm/koa-s3-cache.svg?style=flat-square\n[downloads-url]: https://npmjs.org/package/koa-s3-cache\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fs3-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fs3-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fs3-cache/lists"}