Skip to content

Commit 93553a3

Browse files
authored
Merge pull request #1 from adifiore/redis
Redis
2 parents 5eadc2b + 8a11738 commit 93553a3

11 files changed

+3649
-3
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"name": "react-component-caching",
33
"version": "1.1.0",
4-
"description":
5-
"React Component Caching is a component-level caching library for faster server-side rendering with React 16",
4+
"description": "React Component Caching is a component-level caching library for faster server-side rendering with React 16",
65
"main": "index.js",
76
"scripts": {
8-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"webpack": "./node_modules/.bin/webpack -w"
98
},
109
"keywords": [
1110
"ssr",
@@ -24,5 +23,8 @@
2423
"object-assign": "^4.1.1",
2524
"prop-types": "^15.6.1",
2625
"react": "^16.2.0"
26+
},
27+
"devDependencies": {
28+
"webpack": "^3.5.5"
2729
}
2830
}

src/ComponentCache.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const lru = require('lru-cache');
2+
3+
export default class ComponentCache {
4+
constructor(config = {}) {
5+
if (Number.isInteger(config)) {
6+
config = {
7+
max: config
8+
};
9+
}
10+
11+
this.storage = lru({
12+
max: config.max || 1000000000,
13+
length: (n, key) => {
14+
return n.length + key.length;
15+
}
16+
});
17+
}
18+
19+
get(cacheKey, cb) {
20+
let reply = this.storage.get(cacheKey);
21+
cb(null, reply);
22+
}
23+
24+
set(cacheKey, html) {
25+
this.storage.set(cacheKey, html);
26+
}
27+
}

0 commit comments

Comments
 (0)