Skip to content

Commit d2bedb0

Browse files
committed
memcached setting for streaming
1 parent b5e2b60 commit d2bedb0

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

SSRtest/ModifiedReact.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,6 @@ var ReactDOMServerRenderer = function () {
23872387
out += outCopy.substring(bookmark, outCopy.length);
23882388
}
23892389
} else {
2390-
// console.log(out.length, streamingStart);
23912390
streamingStart.sliceStartCount += out.length;
23922391
}
23932392
return out;
@@ -2698,15 +2697,6 @@ var ReactMarkupReadableStream = function (_Readable) {
26982697
this.streamingStart,
26992698
this.memLife);
27002699
this.push(readOutput);
2701-
// this.push(
2702-
// this.partialRenderer.read(
2703-
// size,
2704-
// this.cache,
2705-
// true,
2706-
// this.streamingStart,
2707-
// this.memLife
2708-
// )
2709-
// );
27102700
} catch (err) {
27112701
this.emit('error', err);
27122702
}
@@ -2736,7 +2726,7 @@ function renderToNodeStream(element, cache, streamingStart, memLife=0) {
27362726
* such as data-react-id that React uses internally.
27372727
* See https://reactjs.org/docs/react-dom-stream.html#rendertostaticnodestream
27382728
*/
2739-
function renderToStaticNodeStream(element, cache, streamingStart, memLife) {
2729+
function renderToStaticNodeStream(element, cache, streamingStart, memLife=0) {
27402730
return new ReactMarkupReadableStream(element, true, cache, streamingStart, memLife);
27412731
}
27422732

SSRtest/src/server/cacheStream.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Transform } from "stream";
22
import { create } from "domain";
33
import { lstat } from "fs";
44

5-
const createCacheStream = (cache, streamingStart) => {
5+
const createCacheStream = (cache, streamingStart, memLife=0) => {
66
const bufferedChunks = [];
77
return new Transform({
88
// transform() is called with each chunk of data
@@ -43,11 +43,15 @@ const createCacheStream = (cache, streamingStart) => {
4343
else tagStack.pop();
4444
}
4545
} while (tagStack.length !== 0);
46-
//console.log(html.slice(streamingStart[component], tagEnd));
4746
// cache component by slicing 'html'
48-
cache.set(component, html.slice(streamingStart[component], tagEnd));
47+
if (memLife) {
48+
cache.set(component, html.slice(streamingStart[component], tagEnd), memLife, (err) => {
49+
if(err) console.log(err)
50+
});
51+
} else {
52+
cache.set(component, html.slice(streamingStart[component], tagEnd));
53+
}
4954
}
50-
//console.log("to be saved:", bufferedChunks.join(""));
5155
cb();
5256
}
5357
});

SSRtest/src/server/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const streamingStart = {
3131
export default ({ clientStats }) => async (req, res) => {
3232
// Need To Come back To If Statement
3333
if(true){
34-
const cacheStream = createCacheStream(cache, streamingStart);
34+
const cacheStream = createCacheStream(cache, streamingStart, 30);
3535
cacheStream.pipe(res);
3636
cacheStream.write(htmlStart);
3737

@@ -45,7 +45,7 @@ export default ({ clientStats }) => async (req, res) => {
4545
const app = <App />;
4646
const start_cached = process.hrtime();
4747

48-
const appString = await ReactCC.renderToStaticMarkup(app, cache, 30);
48+
const appString = await ReactCC.renderToString(app, cache, 30);
4949
const end_cached = process.hrtime(start_cached);
5050
console.info(
5151
"Cached render time: %ds %dms",

SSRtest/src/shared/List.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class List extends Component {
1212
let bunchOfProducts = [];
1313
const templatizedProps = ["name", "description", "price"];
1414
for (let i=0; i<100; i++) {
15-
bunchOfProducts.push(<ProductInfo key={i} name={`Thing ${i}`} description="This product is awesome!" price={i * 10} nonTemplatized="THIS TEXT SHOULD NEVER CHANGE" cache templatized={templatizedProps} />);
15+
bunchOfProducts.push(<ProductInfo key={i} name={`Thing ${i}`} description="This product is awesome!" price={i * 10} nonTemplatized="THIS TEXT SHOULD NEVER CHANGE" cache templatized={templatizedProps}/>);
1616
}
1717
return (
1818
<div>

0 commit comments

Comments
 (0)