{"id":21684368,"url":"https://github.com/knovator/next-redis-cache","last_synced_at":"2025-04-12T07:51:31.323Z","repository":{"id":42702954,"uuid":"300649950","full_name":"knovator/next-redis-cache","owner":"knovator","description":"Next Redis Cache provides middleware/handler to cache server-side rendered page to serving user faster than ever.","archived":false,"fork":false,"pushed_at":"2023-07-11T22:32:23.000Z","size":604,"stargazers_count":20,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T03:04:46.104Z","etag":null,"topics":["hacktoberfest","next-redis-cache","nextjs","nextjs-cache","redis-cache","redis-cache-nextjs"],"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/knovator.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":"2020-10-02T15:00:39.000Z","updated_at":"2024-06-08T08:26:23.000Z","dependencies_parsed_at":"2023-02-06T05:32:00.218Z","dependency_job_id":null,"html_url":"https://github.com/knovator/next-redis-cache","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knovator%2Fnext-redis-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knovator%2Fnext-redis-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knovator%2Fnext-redis-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knovator%2Fnext-redis-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knovator","download_url":"https://codeload.github.com/knovator/next-redis-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142907,"owners_count":21054672,"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":["hacktoberfest","next-redis-cache","nextjs","nextjs-cache","redis-cache","redis-cache-nextjs"],"created_at":"2024-11-25T16:15:28.419Z","updated_at":"2025-04-12T07:51:31.303Z","avatar_url":"https://github.com/knovator.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Next Redis Cache\n\nNext Redis Cache is a Next.js compatible library for caching server rendered pages to serve faster than ever. \n\n\n## Installation\n\nUse the package manager [npm](https://npmjs.com/) or yarn to install next-redis-cache.\n\n```bash\nnpm install next-redis-cache --save\n```\n\nwith yarn package manager.\n\n```bash\nyarn add next-redis-cache\n```\n\n\n## Usage\n\nTo use this package you need to run your app with custom server, read more from here about [next.js custom server](https://nextjs.org/docs/advanced-features/custom-server).\n\nOnce you have next.js custom server setup with your app.\n\n### Use as a middleware\n\n`server.js`\n\n```js\nconst express = require('express')\nconst next = require('next')\nconst NextRedisCache = require('next-redis-cache')\n\n\nconst port = process.env.PORT || 3000\nconst development = process.env.NODE_ENV !== 'production'\nconst app = next({ dev: development })\nconst handler = app.getRequestHandler()\nconst client = redis.createClient()\n\n/**\n *  Initialization of Next Redis Cache instance\n */\nconst nextRedisCache = new NextRedisCache(client, app, {\n  includes: ['/'],  // routes to include for caching\n})\n\napp\n  .prepare()\n  .then(() =\u003e {\n    const server = express()\n\n    server.get('*', \n      (request, response, nxt) =\u003e nextRedisCache.middleware(request, response, nxt), \n      (request, response) =\u003e handler(request, response)\n    )\n\n    /* starting server */\n    return server.listen(port, error =\u003e {\n      if (error) throw error\n      console.log(`\u003e Ready on http://localhost:${port}`)\n    })\n  })\n  .catch(error =\u003e new Error(\"Server isn't responded\", error))\n\n```\n\n### Use as a handler\n\n- To use Next Redis Cache as a request handler just replace Next.js app's handler with nextRedisCache.handler in above snippet, as give in-below.\n\n`server.js`\n\n```js\n    server.get('*', (request, response) =\u003e\n      nextRedisCache.handler(request, response)\n    )\n```\n\nHere, Instance of NextRedisCache initialized with three arguments as following.\n\n|  Name  |          Type         | Required | Default |\n|:------:|:---------------------:|:--------:|:--------:|\n| Client |      Redis Client     |    ✅    |          |\n|   App  |      Next.js App      |    ✅    |          |\n| Config | [Configuration  Object](https://github.com/RajnishKatharotiya/next-redis-cache#configuration) |    ❌    |    {}    |\n\n\n## Configuration\nNext Redis Cache comes with some extra controls to manage your redis database and page's caching. ( it's all in your hand ). \n\nAll you need to know about config object.\n\n| Key           | Detail                                                                                                                  | Type             | Example             | Default        |\n|---------------|-------------------------------------------------------------------------------------------------------------------------|------------------|---------------------|----------------|\n| includes      | Collection of specific routes which should be cache.                                                                    | Array            | ['/', '/blogs/(.*)']   | []             |\n| excludes      | Collection of specific routes which shouldn't be cache.                                                                 | Array            | ['/cart', '/(.*).js'] | [*]            |\n| defaultExpire | Expiration time to expire you cache after a particular time. Note: `null` value of this key will set cache permanently. | Number (Seconds) | 3000                | null           |\n| expire        | To define different expiration time for different routes.                                                               | Number (Seconds) | 3000                | null           |\n| cache         | To disable caching permanently by setting it false.                                                                     | Boolean          | true                | true           |\n| prefix        | To identify your cache in store by unique prefix.                                                                       | String           | \"__my-cache__\"      | \"__my-cache__\" |\n| log           | Log timing of get/set to monitor caching                                                                                | Boolean          | true                | false          |\n\nNote : includes and excludes is using [path-to-regexp](https://www.npmjs.com/package/path-to-regexp) to validate routes.\n\n## Contributing\nPull requests are welcome. For major/valid changes or task from to-do, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n \n### To Do\n- Define Test Cases \n\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknovator%2Fnext-redis-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknovator%2Fnext-redis-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknovator%2Fnext-redis-cache/lists"}