- const ReactCompositeComponent = require("react/lib/ReactCompositeComponent");
- ReactCompositeComponent.Mixin._mountComponent = ReactCompositeComponent.Mixin.mountComponent;
- ReactCompositeComponent.Mixin.mountComponent = function(rootID, transaction, context) {
- const hashKey = generateHashKey(this._currentElement.props);
- if (cacheStorage.hasEntry(hashKey)) {
- // 命中缓存则直接返回缓存结果
- return cacheStorage.getEntry(hashKey);
- } else {
- // 若未命中,则调用react的mountComponent渲染组件,并缓存结果
- const html = this._mountComponent(rootID, transaction, context);
- cacheStorage.addEntry(hashKey, html);
- return html;
- }
- };
- lruCacheSettings: {
- max: 500, // The maximum size of the cache
- maxAge: 1000 * 5 // The maximum age in milliseconds
- }
来源: https://juejin.im/entry/5a378caef265da43128104a8