Skip to content

Commit bf9c46f

Browse files
committed
server.getCacheKey -> serverCacheKey
1 parent c665a68 commit bf9c46f

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

packages/vue-server-renderer/README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,12 @@ const renderer = createRenderer({
173173

174174
## Component-Level Caching
175175

176-
You can easily cache components during SSR by implementing the `server.getCacheKey` function:
176+
You can easily cache components during SSR by implementing the `serverCacheKey` function:
177177

178178
``` js
179179
export default {
180180
props: ['item'],
181-
server: {
182-
getCacheKey: props => props.item.id
183-
},
181+
serverCacheKey: props => props.item.id,
184182
render (h) {
185183
return h('div', this.item.id)
186184
}
@@ -196,9 +194,7 @@ If the renderer hits a cache for a component during render, it will directly reu
196194
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:
197195

198196
``` js
199-
server: {
200-
getCacheKey: props => props.item.id + '::' + props.item.last_updated
201-
}
197+
serverCacheKey: props => props.item.id + '::' + props.item.last_updated
202198
```
203199

204200
## Externals

src/server/render.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function createRenderFunction (
3939
if (node.componentOptions) {
4040
// check cache hit
4141
const Ctor = node.componentOptions.Ctor
42-
const getKey = Ctor.options.server && Ctor.options.server.getCacheKey
42+
const getKey = Ctor.options.serverCacheKey
4343
if (getKey && cache) {
4444
const key = Ctor.cid + '::' + getKey(node.componentOptions.propsData)
4545
if (has) {
@@ -62,7 +62,9 @@ export function createRenderFunction (
6262
} else {
6363
if (getKey) {
6464
console.error(
65-
'Component implemented server.getCacheKey, ' +
65+
`[vue-server-renderer] Component ${
66+
Ctor.options.name || '(anonymous)'
67+
} implemented serverCacheKey, ` +
6668
'but no cache was provided to the renderer.'
6769
)
6870
}

test/ssr/fixtures/cache.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import Vue from '../../../dist/vue.common.js'
22

33
const app = {
44
props: ['id'],
5-
server: {
6-
getCacheKey: props => props.id
7-
},
5+
serverCacheKey: props => props.id,
86
render (h) {
97
return h('div', '/test')
108
}

0 commit comments

Comments
 (0)