-
Notifications
You must be signed in to change notification settings - Fork 7
/
cache.js
47 lines (39 loc) · 994 Bytes
/
cache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* eslint-disable no-console */
// You must install all dependencies (react, lru-cache).
var React = require('react');
var ReactRender = require('../src/index');
var LRU = require('lru-cache');
var cache = LRU({
max: 500,
maxAge: 60 * 60
});
var Component = React.createClass({
displayName: 'Component',
getDefaultProps: function () {
return {
content: 'Some <b>bold</b> text'
};
},
getCacheKey: function () {
return this.props.content;
},
render: function () {
return React.createElement('div', {
className: 'text',
dangerouslySetInnerHTML: {__html: this.props.content}
});
}
});
console.log(
ReactRender.elementToString(
React.createElement(Component),
{cache: cache}
)
);
// Render from cache
console.log(
ReactRender.elementToString(
React.createElement(Component, {content: 'Some <b>bold</b> text'}),
{cache: cache}
)
);