You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-21Lines changed: 37 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,30 +1,30 @@
1
-
# ReactCC
1
+
# React Component Caching
2
2
3
3
## Overview
4
-
ReactCC is a component-level caching library for rendering React components on the server.
4
+
React Component Caching is a component-level caching library for faster server-side rendering with React 16.
5
5
- Use any of React's four server-side rendering methods
6
-
- Cache simple components or templates
6
+
- Cache components using a simple or template strategy
7
7
- Choose from three cache implementations (LRU, Redis, or Memcached)
8
8
9
9
## Installation
10
10
Using npm:
11
11
```shell
12
-
$ npm install reactcc
12
+
$ npm install react-component-caching
13
13
```
14
14
15
15
## Usage
16
16
### In Node rendering server:
17
-
Instantiate a cache and pass it into any rendering method as a second argument. Wherever you would use ReactDOM.renderToString, use ReactCC.renderToString.
17
+
Instantiate a cache and pass it to any rendering method (`renderToString`, `renderToStaticMarkup`, `renderToNodeStream`, or `renderToStaticNodeStream`) as a second argument. Wherever you would use `ReactDOM.renderToString`, use `ReactCC.renderToString`.
18
18
```javascript
19
-
constReactCC=require("reactcc");
19
+
constReactCC=require("react-component-caching");
20
20
constcache=ReactCC.ComponentCache();
21
21
ReactCC.renderToString(<App />, cache>)
22
22
23
23
// ...
24
24
```
25
25
26
26
### In React app:
27
-
To flag a component for caching, simply add a 'cache' property to it. To create a cache template, add both 'cache' and 'templatized', along with an array of props to templatize.
27
+
To flag a component for caching, simply add a `cache` property to it.
<ComponentToTemplatize cache templatized='props to templatize'/>
36
+
</div>
37
+
);
38
+
}
39
+
}
40
+
// ...
41
+
```
42
+
43
+
## Templatizing Cached Components
44
+
The example above employs a simple caching strategy: a rendered component is saved with its prop values. Each time the component is rendered with different prop values, a separate copy is saved to the cache. If a component is frequently rendered with different prop values, you may prefer to cache a template of the component to save space in the cache. The template strategy stores a version of the component with placeholders (e.g. `{{0}}`, `{{1}}`) in place of actual prop values.
45
+
46
+
To create a cache template, add both `cache` and `templatized` to the component along with an array of props to templatize. Templatized props should have **string** or **number** values. **Be aware that templates are not currently supported with the `renderToNodeStream` or `renderToStaticNodeStream` methods.**
ReactCC provides its own cache implementation as well as support for Redis and Memcached. Simply create your preferred cache and pass it into one of the rendering methods.
64
+
React Component Caching provides its own cache implementation as well as support for Redis and Memcached. Simply create your preferred cache and pass it into one of the rendering methods.
ReactCC gives you access to all four of React 16's server-side rendering methods, as well as additional functionality. ReactCC methods are described below.
102
+
React Component Caching gives you access to all four of React 16's server-side rendering methods, as well as additional functionality. Available methods are described below.
87
103
88
104
### ComponentCache
89
105
-`size`: (*Optional*) An integer representing the maximum size (in characters) of the cache. Defaults to 1 million.
@@ -94,7 +110,7 @@ const cache = new ReactCC.ComponentCache();
94
110
```
95
111
96
112
### renderToString
97
-
-`component`: The React component being rendered.
113
+
-`component`: The React component being rendered
98
114
-`cache`: The component cache
99
115
-`memLife`: (*Only if using Memcached*) A number representing the lifetime (in seconds) of each Memcached entry. Defaults to 0.
0 commit comments