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
ReactCC is a component-level caching library for rendering React components on the server.
5
+
- Use any of React's four server-side rendering methods
6
+
- Cache simple components or templates
7
+
- Choose from three cache implementations (LRU, Redis, or Memcached)
8
+
9
+
## Installation
10
+
Using npm:
11
+
```shell
12
+
$ npm install reactcc
13
+
```
14
+
15
+
## Usage
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.
18
+
```javascript
19
+
constReactCC=require("reactcc");
20
+
constcache=ReactCC.ComponentCache();
21
+
ReactCC.renderToString(<App />, cache>)
22
+
23
+
// ...
24
+
```
25
+
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.
28
+
29
+
```javascript
30
+
exportdefaultclassAppextendsComponent {
31
+
render() {
32
+
return (
33
+
<div>
34
+
<ComponentNotToBeCached />
35
+
<ComponentToCache cache />
36
+
<ComponentToTemplatize cache templatized='props to templatize'/>
37
+
</div>
38
+
);
39
+
}
40
+
}
41
+
// ...
42
+
```
43
+
44
+
## Cache Options
45
+
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.
// Make sure to pass in the lifetime of the data (in seconds) as a number.
77
+
ReactCC.renderToString(<App />, cache, 1000);
78
+
```
79
+
80
+
## Templatizing Cached Components
81
+
Insert description and implementation here
82
+
83
+
## API
84
+
85
+
### ReactCC
86
+
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.
87
+
88
+
### ComponentCache
89
+
-`size`: (*Optional*) An integer representing the maximum size (in characters) of the cache. Defaults to 1 million.
90
+
91
+
**Example:**
92
+
```javascript
93
+
constcache=newReactCC.ComponentCache();
94
+
```
95
+
96
+
### renderToString
97
+
-`component`: The React component being rendered.
98
+
-`cache`: The component cache
99
+
-`memLife`: (*Only if using Memcached*) A number representing the lifetime (in seconds) of each Memcached entry. Defaults to 0.
100
+
101
+
**Example:**
102
+
```javascript
103
+
ReactCC.renderToString(<App />, cache);
104
+
```
105
+
106
+
### renderToStaticMarkup
107
+
-`component`: The React component being rendered.
108
+
-`cache`: The component cache
109
+
-`memLife`: (*Only if using Memcached*) An integer representing the lifetime (in seconds) of each Memcached entry. Defaults to 0.
110
+
111
+
**Example:**
112
+
```javascript
113
+
ReactCC.renderToStaticMarkup(<App />, cache);
114
+
```
115
+
116
+
### renderToNodeStream
117
+
-`component`: The React component being rendered.
118
+
-`cache`: The component cache
119
+
-`memLife`: (*Only if using Memcached*) An integer representing the lifetime (in seconds) of each Memcached entry. Defaults to 0.
120
+
121
+
**Example:**
122
+
```javascript
123
+
ReactCC.renderToNodeStream(<App />, cache);
124
+
```
125
+
126
+
### renderToStaticNodeStream
127
+
-`component`: The React component being rendered.
128
+
-`cache`: The component cache
129
+
-`memLife`: (*Only if using Memcached*) An integer representing the lifetime (in seconds) of each Memcached entry. Defaults to 0.
0 commit comments