Skip to content

Commit 6bdf086

Browse files
committed
reformat cache with own get and set methods
1 parent 4fa169d commit 6bdf086

File tree

5 files changed

+43
-28
lines changed

5 files changed

+43
-28
lines changed

SSRtest/ModifiedReact.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,14 +2234,15 @@ var ReactDOMServerRenderer = function () {
22342234
setCurrentDebugStack(this.stack);
22352235
}
22362236

2237-
// IF THE CHILD HAS A CACHEKEY PROPERTY ON IT
2237+
// CACHING LOGIC: EXECUTES IF THE CHILD HAS A 'CACHE' PROP ON IT
22382238
if(child.props.cache){
22392239
const cacheKey = child.type.name + JSON.stringify(child.props);
2240-
if (!cache.storage.get(cacheKey)){
2240+
// console.log(cache.get(cacheKey));
2241+
if (!cache.get(cacheKey)){
22412242
start[cacheKey] = out.length;
22422243
out += this.render(child, frame.context, frame.domNamespace);
22432244
} else {
2244-
out += cache.storage.get(cacheKey);
2245+
out += cache.get(cacheKey);
22452246
}
22462247
} else {
22472248
out += this.render(child, frame.context, frame.domNamespace);
@@ -2270,7 +2271,7 @@ var ReactDOMServerRenderer = function () {
22702271
} while (tagStack.length !== 0);
22712272

22722273
// cache component by slicing 'out'
2273-
cache.storage.set(component, out.slice(start[component], tagEnd));
2274+
cache.set(component, out.slice(start[component], tagEnd));
22742275
}
22752276
return out;
22762277
};
@@ -2613,8 +2614,15 @@ class ComponentCache {
26132614
length: (n, key) => {
26142615
return n.length + key.length;
26152616
}
2616-
});
2617+
});
2618+
}
2619+
2620+
get(cacheKey) {
2621+
return this.storage.get(cacheKey)
2622+
}
26172623

2624+
set(cacheKey, html) {
2625+
this.storage.set(cacheKey, html);
26182626
}
26192627
}
26202628

SSRtest/package-lock.json

Lines changed: 25 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SSRtest/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"react": "^16.2.0",
3535
"react-dom": "^16.2.0",
3636
"react-universal-component": "^2.5.5",
37+
"redis": "^2.8.0",
3738
"webpack-flush-chunks": "^1.1.23",
3839
"winston": "^2.3.1"
3940
},

SSRtest/src/server/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import App from '../shared/App';
99

1010
// can pass in max-size, otherwise defaults to 1 million
1111
const cache = new ReactCC.ComponentCache();
12+
// import redis from 'redis';
13+
// const client = redis.createClient();
1214

1315
/**
1416
* @param clientStats Parameter passed by hot server middleware
@@ -18,6 +20,7 @@ export default ({ clientStats }) => async (req, res) => {
1820
const start_cached = process.hrtime();
1921
// const appString = ReactCC.renderToStaticMarkup(app, cache);
2022
const appString = ReactCC.renderToString(app, cache);
23+
// const appString = ReactCC.renderToString(app, client);
2124
const end_cached = process.hrtime(start_cached);
2225
console.info(
2326
"Cached render time: %ds %dms",

npmPackage/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

33
if (process.env.NODE_ENV === 'production') {
4-
// NOTE: CHANGE TO PRODUCTION WHEN WE HAVE THAT FINAL FILE
5-
module.exports = require('./development.js');
4+
module.exports = require('./production.js');
65
} else {
76
module.exports = require('./development.js');
87
}

0 commit comments

Comments
 (0)