{"_id":"@anonyx88/nuxt3-caching","_rev":"1-824aca74714345b3f9d65fc6f7dfd60f","name":"@anonyx88/nuxt3-caching","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@anonyx88/nuxt3-caching","version":"1.0.0","description":"Page-level caching module for Nuxt.js (multi-stores).","main":"lib/module.js","scripts":{"build":"babel src --out-dir lib","test":"yarn mocha -r chai/register-expect tests","prepublish":"yarn build"},"keywords":["nuxt","ssr","cache","redis","vue","spa"],"author":{"name":"AnonyX"},"license":"MIT","bugs":{"url":"https://8am.us"},"homepage":"https://8am.us","dependencies":{"bluebird":"^3.5.5","cache-manager":"^2.9.1","cache-manager-ioredis":"^2.1.0","cache-manager-memcached-store":"^2.1.0","cache-manager-redis":"^0.6.0","redis":"^4.1.0"},"optionalDependencies":{"cache-manager-ioredis":"^2.1.0","cache-manager-memcached-store":"^2.1.0","cache-manager-redis":"^0.6.0","redis":"^4.1.0"},"devDependencies":{"@babel/cli":"^7.4.4","@babel/core":"^7.4.4","@babel/preset-env":"^7.4.4","chai":"^4.2.0","mocha":"^6.1.4"},"directories":{"test":"tests"},"_id":"@anonyx88/nuxt3-caching@1.0.0","_nodeVersion":"16.14.1","_npmVersion":"8.5.4","dist":{"integrity":"sha512-RU+fxdxkjONJpNVOK5JstyRzPAwjsiK//3pIKDUE+d7neHh0eEZr2uMXHgD+pKLAosyfqge4BVeznCqoffnVPQ==","shasum":"6b60f71d4e1f03e75506c24340937e083943039f","tarball":"https://registry.npmjs.org/@anonyx88/nuxt3-caching/-/nuxt3-caching-1.0.0.tgz","fileCount":4,"unpackedSize":8244,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAdS6frZqT9sXylgTflsNqHAmziwPN0/QGEE6ezgILTkAiBa2rU/iIguoSvWV23cf0WUJgD3CWs1tOURCBj8AaZ5jg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJit6O4ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrOtw//TaahKc05VCYqhAe9eUFc4va86FkOrD0bDwekmRM9DaHlEnA7\r\nf9uvJIw7eoktaXSyqs0uRDlw19rTXmzKD9dN5rsyXZrSja7UnmpNHaYY6a8z\r\nGJgkOPvtOa5vziqs8d3/LJS0lU345k4+RkJVstzhEvY+JmH4+XmM4ns3wchU\r\npCZHWqMgo7VutdgyBQeSs0lbaZIBSnwRvjbCS/F93xGhsUbsJ9UnPbOv5vNC\r\nWQ/LM2Os/xUOnwcF28sAukcYZuO4Xi/iyRkiG5zfWRYRMPg6eaPjGzlzIsGm\r\neID+VVt8umQjqd3OvL6ELRPR70kgUR26WHlqlgIvqiQTC52VOVIQUpa6+cPD\r\n5Z4/I4Wrv/R5tx0XIaGi2x139ZFlZzC2MCEfvHXCCy0kuhXFEv+qMWZxjOfQ\r\ncMrAdHbICXgZvWOxrlH/hXodV3hVpOXf51NPyYi7YWB2ZQM+dnEeGro6sE17\r\n/E7ug2bMf11TlEbjjXab1nBLMwcuMSgLI83qyr/Ck+8i41l7ItKKFhW1b3fP\r\nTROhIa0SchdOxSYCc8sF1UvTwIiJraFI57B66OVrHpbtH2ME+x9DJmWqEi8q\r\ne21eLIh5VH0FblJcShEBDpAFHb0BjKop8jdgzF+Jt+roSF6X+b8OQKbHFln0\r\nzZ//fJHAT/QerPsX0y9CSGxfFLzomCHC6gU=\r\n=k85n\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"anonyx88","email":"vietvd.com@gmail.com"},"maintainers":[{"name":"anonyx88","email":"vietvd.com@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nuxt3-caching_1.0.0_1656202167812_0.44015545144047485"},"_hasShrinkwrap":false},"1.0.1":{"name":"@anonyx88/nuxt3-caching","version":"1.0.1","description":"Page-level caching module for Nuxt.js (multi-stores).","main":"lib/module.js","scripts":{"build":"babel src --out-dir lib","test":"yarn mocha -r chai/register-expect tests","prepublish":"npm build"},"keywords":["nuxt","ssr","cache","redis","vue","spa"],"author":{"name":"AnonyX"},"license":"MIT","bugs":{"url":"https://8am.us"},"homepage":"https://8am.us","dependencies":{"bluebird":"^3.5.5","cache-manager":"^2.9.1","cache-manager-ioredis":"^2.1.0","cache-manager-memcached-store":"^2.1.0","cache-manager-redis":"^0.6.0","redis":"^4.1.0"},"optionalDependencies":{"cache-manager-ioredis":"^2.1.0","cache-manager-memcached-store":"^2.1.0","cache-manager-redis":"^0.6.0","redis":"^4.1.0"},"devDependencies":{"@babel/cli":"^7.4.4","@babel/core":"^7.4.4","@babel/preset-env":"^7.4.4","chai":"^4.2.0","mocha":"^6.1.4"},"directories":{"test":"tests"},"_id":"@anonyx88/nuxt3-caching@1.0.1","_nodeVersion":"16.14.1","_npmVersion":"8.5.4","dist":{"integrity":"sha512-LxqiVO8m86VyHoBvzcWszY5BzIgjm2Gm4lYIs9AnT904rFnelPBOgiDzAnnRbKXuJzJR5cIA6IE92/B+261y9Q==","shasum":"8f12c5ec9a6a731275545de71918967f957a9581","tarball":"https://registry.npmjs.org/@anonyx88/nuxt3-caching/-/nuxt3-caching-1.0.1.tgz","fileCount":7,"unpackedSize":19485,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIApQUbN1m8oZsvsBt+IJJZgYjPXYnOshJSmSf4ykXw2AAiEApKWU9l1puLqA7mHHEC2UCTD55MTtM5Aieo+YAqKGqw4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJit6dhACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrBjBAAhpImbTS8zcHUVodRvKoL+5qJ0KblgSSD6rXmlWGa2rbpN3/h\r\nXjSSHCHb5+S1EXdvpOnlqnkFJNP5FPz7iRRG4YHGMKDpK5RAEw63hevxuxad\r\n4eHzgCjMPyhqIaWQhEUpTIj7ydxf3ewA5Uma1K9NgLwhQ04eoTECbxIMYpjm\r\nHY7TJOkBNGazFp/nUgO7gWjzEdPq1s/hx977YSEqlX5OWp9isZEDUv7MsBtO\r\n9RaYmf4NFYU6h8rfLYa6/mVDeDNNI3O1z4rJhwNqWsPE6PL4P92GCgF7ounF\r\npaJeoNnPxQJ3IWnIZFg5ip6SPoY4sB8RGVr1oGoRmyVGBus3gG6Ew+GysXnr\r\nULFjpFpTNR/x1aY5egdzu8rCFm1hEOGm433+TPFFxtB90r7PlDlM+8bWO38j\r\nSJIl8QH9yuXTY6KVUrp+i8g3180XF+DOJrOi2QvjvqOFpDwYeyOxJd8WHMxm\r\nC1fn1/MPA8PBdDBAqIEE+/0bHOvGEDANTsHieKFJa9bkMgO1pn5XB2FKIKzC\r\n1MgDqaTjs4y6doXUq5tuXkQ0lEjqpVPnAYYqi0gSAR/IiDRTAwyupYhZ50Ez\r\na1sZCr6KxWDy4WQQgnya6EsCPZHBgt5cIxbv39RgQ1U8OvEH86GQ30ugMSmc\r\nAOlU/6jHYZHABnRqdm0SvWOAmCPg/8zSU+M=\r\n=UQwb\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"anonyx88","email":"vietvd.com@gmail.com"},"maintainers":[{"name":"anonyx88","email":"vietvd.com@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nuxt3-caching_1.0.1_1656203105505_0.501530530960401"},"_hasShrinkwrap":false}},"time":{"created":"2022-06-26T00:09:27.751Z","1.0.0":"2022-06-26T00:09:27.980Z","modified":"2022-06-26T00:25:05.739Z","1.0.1":"2022-06-26T00:25:05.673Z"},"maintainers":[{"name":"anonyx88","email":"vietvd.com@gmail.com"}],"description":"Page-level caching module for Nuxt.js (multi-stores).","homepage":"https://8am.us","keywords":["nuxt","ssr","cache","redis","vue","spa"],"author":{"name":"AnonyX"},"bugs":{"url":"https://8am.us"},"license":"MIT","readme":"# @anonyx88/nuxt3-caching\n[![NPM version](https://img.shields.io/npm/v/@anonyx88/nuxt3-caching.svg)](https://www.npmjs.com/package/@anonyx88/nuxt3-caching)\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 @anonyx88/nuxt3-caching\n\n# or npm\nnpm install @anonyx88/nuxt3-caching\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        ['@anonyx88/nuxt3-caching', options],\n        // ...\n    ]\n}\n```\n2. Or you can provide `cache` property in `nuxt.config.js`:\n```javascript\nmodule.exports = {\n    modules: [\n        '@anonyx88/nuxt3-caching',\n        // ...\n    ],\n\n    cache: {\n        // ...\n    },\n}\n```\n\n### Page Cache Options\n\n```javascript\nmodule.exports = {\n  // ....\n\n  modules: [\n    '@anonyx88/nuxt3-caching',\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 -> content hash changed -> assets URL changed. I recommend to use CI build number if you are using CI/CD.\n\n## License\nMIT\n","readmeFilename":"README.md"}