{"id":26659295,"url":"https://github.com/kimyvgy/nuxt-page-cache","last_synced_at":"2025-04-11T14:10:46.181Z","repository":{"id":57124789,"uuid":"406710817","full_name":"kimyvgy/nuxt-page-cache","owner":"kimyvgy","description":"nuxt-page-cache is a module for page-level caching","archived":false,"fork":false,"pushed_at":"2023-09-26T08:52:46.000Z","size":17,"stargazers_count":29,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T20:04:10.626Z","etag":null,"topics":["cache","hacktoberfest","ioredis","memcached","memory-cache","nuxt","pagecache","redis"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@kimyvgy/nuxt-page-cache","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/kimyvgy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"patreon":"devsuccess101","custom":["https://paypal.me/kimyvgy"]}},"created_at":"2021-09-15T10:10:56.000Z","updated_at":"2024-05-24T10:57:22.000Z","dependencies_parsed_at":"2024-10-23T20:43:21.754Z","dependency_job_id":"e5627cd4-0da3-479b-ae9b-d8cc5a2b7373","html_url":"https://github.com/kimyvgy/nuxt-page-cache","commit_stats":{"total_commits":33,"total_committers":2,"mean_commits":16.5,"dds":"0.030303030303030276","last_synced_commit":"29564ffb7a6816cbafd144ff8dbf9f10a67f1461"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimyvgy%2Fnuxt-page-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimyvgy%2Fnuxt-page-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimyvgy%2Fnuxt-page-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimyvgy%2Fnuxt-page-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kimyvgy","download_url":"https://codeload.github.com/kimyvgy/nuxt-page-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248414099,"owners_count":21099414,"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","hacktoberfest","ioredis","memcached","memory-cache","nuxt","pagecache","redis"],"created_at":"2025-03-25T10:20:12.405Z","updated_at":"2025-04-11T14:10:46.145Z","avatar_url":"https://github.com/kimyvgy.png","language":"JavaScript","funding_links":["https://patreon.com/devsuccess101","https://paypal.me/kimyvgy"],"categories":[],"sub_categories":[],"readme":"# @kimyvgy/nuxt-page-cache\n[![NPM version](https://img.shields.io/npm/v/@kimyvgy/nuxt-page-cache.svg)](https://www.npmjs.com/package/@kimyvgy/nuxt-page-cache)\n\nPage-level caching module for Nuxt.js (multi-stores).\n\nThis module is based on [arash16/nuxt-ssr-cache](https://github.com/arash16/nuxt-ssr-cache) with more features added.\n\n## Supported Stores\n\n- [Memory](#page-cache-options)\n- [Redis](#redis-store)\n- [Memcached](#memcached-store)\n- [IORedis](#ioredis-store)\n- [Multi cache layered](#multi-cache-layered)\n\n## Installation\n\nInstall via NPM/Yarn:\n\n```bash\n# yarn\nyarn add @kimyvgy/nuxt-page-cache\n\n# or npm\nnpm install @kimyvgy/nuxt-page-cache\n```\n\n## Setup\n\n### Configuration\n\nPlease activate this module in `nuxt.config.js`:\n1. Passing options directly\n```javascript\nmodule.exports = {\n    modules: [\n        ['@kimyvgy/nuxt-page-cache', options],\n        // ...\n    ]\n}\n```\n2. Or you can provide `cache` property in `nuxt.config.js`:\n```javascript\nmodule.exports = {\n    modules: [\n        '@kimyvgy/nuxt-page-cache',\n        // ...\n    ],\n\n    cache: {\n        // ...\n    },\n}\n```\n\n### Page Cache Options\n\n```javascript\nmodule.exports = {\n  // ....\n\n  modules: [\n    '@kimyvgy/nuxt-page-cache',\n  ],\n\n  cache: {\n    // enable page-cache module for the production only\n    enabled: process.env.NODE_ENV === 'production',\n\n    // add x-cache-status header into response:\n    // MISS: The page was not found in Cache Storage\n    // HIT: The page was found in Cache Storage\n    // NONE: The page is not eligible for caching\n    cacheStatusHeader: 'x-cache-status',\n\n    // The name of function that can be used to set cacheStatusHeader.\n    // Ex: - Express: 'set'\n    //     - Connect: 'setHeader' (default of Nuxt.js)\n    // setHeaderFunc: 'setHeader',\n\n    // If you provide a version, it will be stored inside cache.\n    // Later when you deploy a new version, old cache will be\n    // automatically purged.\n    // EX: `myapp.v${pkg.version}-build-${process.env.CI_BUILD_NUMBER}`\n    version: pkg.version,\n\n    // if you're serving multiple host names (with differing\n    // results) from the same server, set this option to true.\n    // (cache keys will be prefixed by your host name)\n    // if your server is behind a reverse-proxy, please use\n    // express or whatever else that uses 'X-Forwarded-Host'\n    // header field to provide req.hostname (actual host name)\n    useHostPrefix: false,\n\n    pages: [\n      // these are prefixes of pages that need to be cached\n      // if you want to cache all pages, just include '/'\n      '/page1', // will cache all pages: /page1*\n      '/page2', // will cache all pages: /page2*\n\n      // you can also pass a regular expression to test a path\n      /^\\/page3\\/\\d+$/,\n\n      // to cache only root route, use a regular expression\n      /^\\/$/, // will cache only for homepage: /\n    ],\n\n    key(route, context) {\n      // custom function to return cache key, when used previous\n      // properties (useHostPrefix, pages) are ignored.\n      // - return falsy value to bypass the cache\n      // - return string value to cache this page with default TTL value.\n      // - return { key: \"your_cache_key\", ttl: 84600 }\n      //    to return cache key with customized TTL value.\n      if (/\\/articles\\/.+/.test(context.req.url)) {\n        return { key: context.req.url, ttl: 84600 } // 1 day for page: /articles/*\n      }\n    },\n\n    // if you don't use `pages` property, you can define `isCacheable` instead\n    /*\n    isCacheable(route, context) {\n        // custom function to decide this page that need to be cached,\n        // when used the \"pages\" property will be ignored.\n        // return falsy to bypass the cache.\n    },\n    */\n\n    // cache storage configuration\n    store: {\n      type: 'memory',\n\n      // maximum number of pages to store in memory\n      // if limit is reached, least recently used page\n      // is removed.\n      max: 100,\n\n      // number of seconds to store this page in cache,\n      // default TTL value for all pages.\n      ttl: 60,\n    },\n  },\n\n  // ...\n};\n```\n\n### `redis` store\n\n```javascript\nmodule.exports = {\n  // ....\n  cache: {\n    // ....\n    store: {\n      type: 'redis',\n      host: process.env.REDIS_HOST || 'localhost',\n      port: process.env.REDIS_PORT || 6379,\n      password: process.env.REDIS_PASSWORD,\n      db: process.env.REDIS_DB,\n      prefix: process.env.REDIS_PREFIX,\n      ttl: 600, // seconds\n      configure: [\n        // these values are configured\n        // on redis upon initialization\n        ['maxmemory', '200mb'],\n        ['maxmemory-policy', 'allkeys-lru'],\n      ],\n    },\n  },\n}\n```\nUses [cache-manager-redis](https://www.npmjs.com/package/cache-manager-redis) under the hood.\n\n### `memcached` store\n\n```javascript\nmodule.exports = {\n  // ....\n  cache: {\n    // ....\n    store: {\n      type: 'memcached',\n      options: {\n        hosts: ['127.0.0.1:11211'],\n      },\n    },\n  },\n}\n```\nUses [cache-manager-memcached-store](https://www.npmjs.com/package/cache-manager-memcached-store) under the hood.\n\n### `ioredis` store\n\n```javascript\nmodule.exports = {\n  // ....\n  cache: {\n    // ....\n    store: {\n      type: 'ioredis',\n      options: {\n        hosts: ['localhost:6379'],\n      },\n    },\n  },\n}\n```\nUses [cache-manager-ioredis](https://www.npmjs.com/package/cache-manager-ioredis) under the hood.\n\n### `multi` cache (layered)\n\n```javascript\nmodule.exports = {\n  // ....\n  cache: {\n    // ....\n    store: {\n      // multi cache stores pages in all caches\n      // later tries to read them in sequential order\n      // in this example it first tries to read from memory\n      // if not found, it tries to read from redis\n      type: 'multi',\n      stores: [\n        { type: 'memory', /* ... */ },\n        { type: 'redis', /* ... */ },\n      ],\n    },\n  },\n}\n```\n\n## Notes\n\n- `version` property can define at root-level of `nuxt.config.js` or inside module options.\n- `version` value must be uniqued for each release to make sure the cached pages are pured after deploying to production. Your code changed -\u003e content hash changed -\u003e assets URL changed. I recommend to use CI build number if you are using CI/CD.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimyvgy%2Fnuxt-page-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkimyvgy%2Fnuxt-page-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimyvgy%2Fnuxt-page-cache/lists"}