![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
next-storage-provider
Advanced tools
A Next.JS plugin to store ISR rendered pages using Redis for caching and compatible with Amazon S3 like APIs
A Next.JS plugin to store and cache ISR rendered pages using Redis and Amazon S3 like APIs
Using a custom storage provider in Next.JS is currently NOT supported (and probably won't be in the near future) and this plugin relies on this pull request made by MartinLG.
If you want to use this plugin you must use the extends-storage-and-cache branch from his Next.JS's fork or modify and compile Next yourself.
yarn install next-storage-provider
Create a next.config.js
in your project.
Next-storage-provider works out of the box with the default configuration file of Redis (not recommended)
// next.config.js
const withStorageProvider = require("next-storage-provider");
module.exports = withStorageProvider({
redis: {},
});
With next-compose-plugins
// next.config.js
const withPlugins = require("next-compose-plugins");
const withStorageProvider = require("next-storage-provider");
module.exports = withPlugins([
[
withStorageProvider,
{
redis: {},
},
],
]);
Redis should be set as an LRU (or LFU) cache using the maxmemory
directive with an eviction policy of your choice.
See Using Redis as an LRU cache for more.
This plugin uses ioredis as Redis client.
You can either pass an existing ioredis
client or pass an object with ioredis
options.
const Redis = require("ioredis");
const redisClient = new Redis({
host: "127.0.0.1",
port: 7000,
});
const withStorageProvider = require("next-storage-provider");
module.exports = withStorageProvider({
redis: redisClient,
});
or
const withStorageProvider = require("next-storage-provider");
module.exports = withStorageProvider({
redis: {
host: "127.0.0.1",
port: 6380,
username: "user",
passoword: "password",
},
});
Redis only.
The prefix that will be used for the key in redis.
Defaults to next_cache
.
module.exports = withStorageProvider({
prefix: "my_prefix",
});
Redis only.
If set to true
, whenever trying to get the cache or storing a page fails, a per-process LRU cache will be used as fallback to get/store pages.
Defaults to false
.
module.exports = withStorageProvider({
redis: {},
fallback: true,
});
Only used when fallback
is used.
Sets the maximum size of the cache.
Defaults to 50 MB.
module.exports = withStorageProvider({
max: 100 * 1024 * 1024, // 100 MB,
});
Whether cached pages should be removed from Redis after their revalidate time has passed.
If a cached entry expires, no cached content will be sent and the user will receive the rendered page after Next is done rendering.
This way you can avoid showing a cached entry to the user that will trigger a page re-render after revalidate.
Defaults to false
.
module.exports = withStorageProvider({
redis: {},
expire: true,
});
If set to true
, an Amazon S3 like object storage will be used to get/store generated HTML and JSON page files and a per-process LRU cache will be used instead.
Files are only requested if the page data is missing from the cache, and are only stored when a page is regenerated (2 requests per page are made when getting or storing data, as the HTML and JSON (page props) are stored separately).
Next-storage-provider uses MinIO-JS as S3 client.
You can find all the options available in MinIO's documentation.
Example with Amazon S3:
const withStorageProvider = require("next-storage-provider");
module.exports = withStorageProvider({
useS3: true,
S3Config: {
endPoint: "s3.amazonaws.com",
accessKey: "YOUR-ACCESSKEYID",
secretKey: "YOUR-SECRETACCESSKEY",
},
});
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Both ESlint and Prettier checks must pass:
yarn run lint
yarn run prettier
Run both ESLint and Prettier on all files:
yarn run format
If changing the README:
yarn run prettier:readme
yarn run format:readme
Copyright © 2021 reboxer (https://github.com/reboxer).
This project is MIT licensed.
FAQs
A Next.JS plugin to store ISR rendered pages using Redis for caching and compatible with Amazon S3 like APIs
The npm package next-storage-provider receives a total of 0 weekly downloads. As such, next-storage-provider popularity was classified as not popular.
We found that next-storage-provider demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.