react-server-data-bundle-cache

0.8.1 • Public • Published

React-server data bundle cache

Cache the data for react-server pages for blazing fast client transitions.

Usage

First, install the module:

npm install --save react-server-data-bundle-cache

Then, install the cache:

import DataBundleCache from "react-server-data-bundle-cache"
 
DataBundleCache.install();

Then, opt into bundle caching in pages:

class MyPage {
    handleRoute() {
        DataBundleCache.optIn();
        ...
    }
    ...
}

Then, link to your page with the bundleData option:

<Link bundleData={true} path="/mypage">My page</Link>

If you really want to be slick, preload the bundle:

DataBundleCache.preload('/mypage');

Options:

  • ttl: How long (in milliseconds) a bundle is good for.
  • max: How many bundles may be kept in the cache.

Pass options as an object to the install method:

DataBundleCache.install({
    ttl: 10*60*1000, // Ten minutes.
    max: 10,         // Ten bundles.
});

That's it! Enjoy! 🚀

Readme

Keywords

none

Package Sidebar

Install

npm i react-server-data-bundle-cache

Weekly Downloads

3

Version

0.8.1

License

Apache License 2.0

Last publish

Collaborators

  • avastu
  • douglas.wade
  • drewpc
  • gigabo
  • sresant