Skip to content

Commit

Permalink
Merge pull request #3370 from Automattic/update/server-lru-lib
Browse files Browse the repository at this point in the history
Server Side Rendering: Use lru-cache instead of LruMap
  • Loading branch information
ehg committed Feb 17, 2016
2 parents 08ae0da + 5b40197 commit fe03131
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 54 deletions.
51 changes: 1 addition & 50 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"localforage": "1.3.3",
"lodash": "3.10.1",
"lru-cache": "4.0.0",
"lru-map": "1.2.0",
"lunr": "0.5.7",
"marked": "0.3.5",
"moment": "2.10.6",
Expand Down
8 changes: 5 additions & 3 deletions server/render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import ReactDomServer from 'react-dom/server';
import Helmet from 'react-helmet';
import memoize from 'lodash/function/memoize';
import superagent from 'superagent';
import LruMap from 'lru-map';
import Lru from 'lru-cache';

/**
* Internal dependencies
*/
import config from 'config';

const markupCache = new Lru( { max: 1000 } );
const memoizedRenderToString = memoize( ReactDomServer.renderToString, element => JSON.stringify( element ) );
memoizedRenderToString.cache = new LruMap( { maxSize: 1000 } );

function bumpStat( group, name ) {
const url = `http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_${ group }=${ name }&t=${ Math.random() }`;
Expand All @@ -24,7 +24,9 @@ function bumpStat( group, name ) {
}

export function render( element ) {
if ( ! memoizedRenderToString.cache.has( element ) ) {
memoizedRenderToString.cache = markupCache;

if ( ! memoizedRenderToString.cache.has( JSON.stringify( element ) ) ) {
bumpStat( 'calypso-ssr', 'loggedout-design-cache-miss' );
}

Expand Down

0 comments on commit fe03131

Please sign in to comment.