{"id":16153741,"url":"https://github.com/bradoyler/route-cache","last_synced_at":"2025-04-05T08:09:49.494Z","repository":{"id":520417,"uuid":"21511918","full_name":"bradoyler/route-cache","owner":"bradoyler","description":"⚡ Caching middleware for Express (w/ expiration)","archived":false,"fork":false,"pushed_at":"2024-06-16T12:03:59.000Z","size":495,"stargazers_count":94,"open_issues_count":3,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-11T01:14:18.921Z","etag":null,"topics":[],"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/bradoyler.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":"2014-07-05T02:36:57.000Z","updated_at":"2024-08-06T12:50:26.000Z","dependencies_parsed_at":"2024-01-11T17:19:38.934Z","dependency_job_id":"38198df6-c735-4704-b36b-4b3ec4f78d21","html_url":"https://github.com/bradoyler/route-cache","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradoyler%2Froute-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradoyler%2Froute-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradoyler%2Froute-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradoyler%2Froute-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bradoyler","download_url":"https://codeload.github.com/bradoyler/route-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305935,"owners_count":20917208,"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":[],"created_at":"2024-10-10T01:14:21.198Z","updated_at":"2025-04-05T08:09:49.468Z","avatar_url":"https://github.com/bradoyler.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Route-Cache\nBlazing fast :bullettrain_side: Express middleware for route caching with a given TTL (in seconds)\n\n[![Build Status](https://github.com/bradoyler/route-cache/actions/workflows/node.js.yml/badge.svg)](https://github.com/bradoyler/route-cache/actions/workflows/node.js.yml)\n[![NPM Version][npm-image]][npm-url]\n[![Downloads][downloads-image]][npm-url]\n\n[![NPM](https://nodei.co/npm/route-cache.png?downloads=true\u0026downloadRank=true)](https://nodei.co/npm/route-cache/) [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n## Why?\n- makes hard-working routes super-fast, under heavy-load, [see Load Tests](loadtests)\n- defend against 'thundering herd'\n- supports various content-types\n- support for redirects\n- allows for conditional caching (per request)\n- works with gzip compression\n\n## Install\n```sh\nnpm install route-cache\n```\n\n## Test\n```sh\nnpm test\n```\n\n## How to use\n```javascript\nvar routeCache = require('route-cache');\n\n// cache route for 20 seconds\napp.get('/index', routeCache.cacheSeconds(20), function(req, res){\n  // do your dirty work here...\n  console.log('you will only see this every 20 seconds.');\n  res.send('this response will be cached');\n});\n```\n\nBy default `req.originalUrl` is used as the cache key so every URL is cached separately.\n\nYou can set a custom key by passing a second argument to `cacheSeconds`.\n\n```javascript\nrouteCache.cacheSeconds(20, 'my-custom-cache-key')\n```\n\nYou can set a dynamic key from the `req` and `res` objects by passing a function.\n\n```javascript\n// Cache authenticated and unauthenticated responses separately\nrouteCache.cacheSeconds(20, function(req, res) {\n  return req.originalUrl + '|' + res.locals.signedIn\n})\n```\n\nIf you return `false` the response will not be cached.\n\n```javascript\n// Only cache unauthenticated responses\nrouteCache.cacheSeconds(20, function(req, res) {\n  if (res.locals.signedIn) { return false }\n\n  return req.originalUrl\n})\n```\n\n## Delete a cached route\n```javascript\nrouteCache.removeCache('/index');\n```\n\n## Use a distributed cache\n```javascript\nconst Redis = require('ioredis')\nconst IoRedisStore = require('route-cache/ioRedisStore')\n\n\nconst redisClient = new Redis(6379, '127.0.0.1'))\nconst cacheStore = new IoRedisStore(redisClient)\nrouteCache.config({cacheStore})\n```\n\n## Future plans / todos\n- client-side Cache-Control\n\n------\nThe MIT License (MIT)\n\nCopyright (c) 2014 Brad Oyler\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n[npm-image]: https://img.shields.io/npm/v/route-cache.svg\n[downloads-image]: http://img.shields.io/npm/dm/route-cache.svg\n[npm-url]: https://npmjs.org/package/route-cache\n[gha-workflow]: https://github.com/bradoyler/route-cache/actions/workflows/node.js.yml","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradoyler%2Froute-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbradoyler%2Froute-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradoyler%2Froute-cache/lists"}