Skip to content

Commit b26ec09

Browse files
committed
update ssr cache documentation
1 parent 42889ff commit b26ec09

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

packages/vue-server-renderer/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ As an example, check out [`v-show`'s server-side implementation](https://github.
149149

150150
> Note: this option has changed and is different from versions <= 2.0.0-alpha.8.
151151
152-
Provide a cache implementation. The cache object must be of the following shape:
152+
Provide a cache implementation. The cache object must implement the following interface:
153153

154154
``` js
155155
{
156-
get: (key: string) => string,
156+
get: (key: string, [cb: Function]) => string | void,
157157
set: (key: string, val: string) => void,
158-
has?: (key: string) => boolean // optional
158+
has?: (key: string, [cb: Function]) => boolean | void // optional
159159
}
160160
```
161161

@@ -171,6 +171,24 @@ const renderer = createRenderer({
171171
})
172172
```
173173

174+
Note that the cache object should at least implement `get` and `set`. In addition, `get` and `has` can be optionally async if they accept a second argument as callback. This allows the cache to make use of async APIs, e.g. a redis client:
175+
176+
``` js
177+
const renderer = createRenderer({
178+
cache: {
179+
get: (key, cb) => {
180+
redisClient.get(key, (err, res) => {
181+
// handle error if any
182+
cb(res)
183+
})
184+
},
185+
set: (key, val) => {
186+
redisClient.set(key, val)
187+
}
188+
}
189+
})
190+
```
191+
174192
## Component-Level Caching
175193

176194
You can easily cache components during SSR by implementing the `serverCacheKey` function:

0 commit comments

Comments
 (0)