浏览代码

server.getCacheKey -> serverCacheKey

Evan You 9 年之前
父节点
当前提交
bf9c46f435
共有 3 个文件被更改,包括 8 次插入12 次删除
  1. 3 7
      packages/vue-server-renderer/README.md
  2. 4 2
      src/server/render.js
  3. 1 3
      test/ssr/fixtures/cache.js

+ 3 - 7
packages/vue-server-renderer/README.md

@@ -173,14 +173,12 @@ const renderer = createRenderer({
 
 ## Component-Level Caching
 
-You can easily cache components during SSR by implementing the `server.getCacheKey` function:
+You can easily cache components during SSR by implementing the `serverCacheKey` function:
 
 ``` js
 export default {
   props: ['item'],
-  server: {
-    getCacheKey: props => props.item.id
-  },
+  serverCacheKey: props => props.item.id,
   render (h) {
     return h('div', this.item.id)
   }
@@ -196,9 +194,7 @@ If the renderer hits a cache for a component during render, it will directly reu
 In most cases, you shouldn't and don't need to cache single-instance components. The most common type of components that need caching are ones in big lists. Since these components are usually driven by objects in database collections, they can make use of a simple caching strategy: generate their cache keys using their unique id plus the last updated timestamp:
 
 ``` js
-server: {
-  getCacheKey: props => props.item.id + '::' + props.item.last_updated
-}
+serverCacheKey: props => props.item.id + '::' + props.item.last_updated
 ```
 
 ## Externals

+ 4 - 2
src/server/render.js

@@ -39,7 +39,7 @@ export function createRenderFunction (
     if (node.componentOptions) {
       // check cache hit
       const Ctor = node.componentOptions.Ctor
-      const getKey = Ctor.options.server && Ctor.options.server.getCacheKey
+      const getKey = Ctor.options.serverCacheKey
       if (getKey && cache) {
         const key = Ctor.cid + '::' + getKey(node.componentOptions.propsData)
         if (has) {
@@ -62,7 +62,9 @@ export function createRenderFunction (
       } else {
         if (getKey) {
           console.error(
-            'Component implemented server.getCacheKey, ' +
+            `[vue-server-renderer] Component ${
+              Ctor.options.name || '(anonymous)'
+            } implemented serverCacheKey, ` +
             'but no cache was provided to the renderer.'
           )
         }

+ 1 - 3
test/ssr/fixtures/cache.js

@@ -2,9 +2,7 @@ import Vue from '../../../dist/vue.common.js'
 
 const app = {
   props: ['id'],
-  server: {
-    getCacheKey: props => props.id
-  },
+  serverCacheKey: props => props.id,
   render (h) {
     return h('div', '/test')
   }