{"id":15046553,"url":"https://github.com/vicanso/koa-varnish","last_synced_at":"2026-01-30T09:25:21.461Z","repository":{"id":143882920,"uuid":"91704709","full_name":"vicanso/koa-varnish","owner":"vicanso","description":"The cache middleware for koa, it can cache the data such as varnish.","archived":false,"fork":false,"pushed_at":"2017-05-20T07:52:43.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-01T21:47:42.493Z","etag":null,"topics":["cache","koa","varnish"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vicanso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-18T14:42:35.000Z","updated_at":"2022-10-10T01:33:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"09af160a-1b66-4785-99a6-383d474572ce","html_url":"https://github.com/vicanso/koa-varnish","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vicanso/koa-varnish","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fkoa-varnish","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fkoa-varnish/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fkoa-varnish/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fkoa-varnish/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vicanso","download_url":"https://codeload.github.com/vicanso/koa-varnish/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fkoa-varnish/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260496721,"owners_count":23018141,"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","varnish"],"created_at":"2024-09-24T20:53:13.814Z","updated_at":"2026-01-30T09:25:21.398Z","avatar_url":"https://github.com/vicanso.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-varnish\n\n[![Build Status](https://travis-ci.org/vicanso/koa-varnish.svg?style=flat-square)](https://travis-ci.org/vicanso/koa-varnish)\n[![Coverage Status](https://img.shields.io/coveralls/vicanso/koa-varnish/master.svg?style=flat)](https://coveralls.io/r/vicanso/koa-varnish?branch=master)\n[![npm](http://img.shields.io/npm/v/koa-varnish.svg?style=flat-square)](https://www.npmjs.org/package/koa-varnish)\n[![Github Releases](https://img.shields.io/npm/dm/koa-varnish.svg?style=flat-square)](https://github.com/vicanso/koa-varnish)\n\nThe cache middleware for koa, it can cache the data such as varnish. The cache ttl is use the value of `s-maxage` or `maxage` from response header: `Cache-Control`.\n\nUncacheable list:\n\n- Method isn't 'GET' or 'HEAD'\n- Function isCacheable return false\n- HTTP response status is not 200, 203, 204, 300, 301, 302, 304, 307, 404, 410, 414\n- Get max-age from response header `Cache-Control` isn't gt 0\n\n## Installation\n\n```bash\n$ npm i koa-varnish\n```\n\n## API\n\n- `hash` Get the key for the cache, default is `${ctx.method}-${ctx.url}`\n- `isCacheable` Check the request is cacheable, default is all true.\n- `cache` The opotions for lru-cache\n- `hitForPass` The max-age for hit for pass, default is `300 * 1000`ms\n\n```js\nconst cache = require('koa-varnish');\nconst Koa = require('koa');\nconst app = new Koa();\n\napp.use(cache({\n  hash: ctx =\u003e ctx.url,\n  isCacheable: (ctx) =\u003e {\n    if (ctx.url.indexOf('/user') === 0) {\n      return false;\n    }\n    return true;\n  },\n}));\n\napp.use(ctx =\u003e {\n\tif (ctx.url === '/wait') {\n    return new Promise(function(resolve, reject) {\n      ctx.set('Cache-Control', 'private, max-age=10');\n      ctx.body = 'Wait for 1000ms';\n      setTimeout(resolve, 1000);\n    });\n\t} else {\n    ctx.set('Cache-Control', 'public, max-age=10')\n    ctx.body = 'Hello World';\n\t}\n});\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicanso%2Fkoa-varnish","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvicanso%2Fkoa-varnish","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicanso%2Fkoa-varnish/lists"}