From b26ec09eb2108579c174b8a1d896f2b892e21e82 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 7 Jul 2016 16:35:24 -0400 Subject: [PATCH] update ssr cache documentation --- packages/vue-server-renderer/README.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/vue-server-renderer/README.md b/packages/vue-server-renderer/README.md index 607e0188..2da91713 100644 --- a/packages/vue-server-renderer/README.md +++ b/packages/vue-server-renderer/README.md @@ -149,13 +149,13 @@ As an example, check out [`v-show`'s server-side implementation](https://github. > Note: this option has changed and is different from versions <= 2.0.0-alpha.8. -Provide a cache implementation. The cache object must be of the following shape: +Provide a cache implementation. The cache object must implement the following interface: ``` js { - get: (key: string) => string, + get: (key: string, [cb: Function]) => string | void, set: (key: string, val: string) => void, - has?: (key: string) => boolean // optional + has?: (key: string, [cb: Function]) => boolean | void // optional } ``` @@ -171,6 +171,24 @@ const renderer = createRenderer({ }) ``` +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: + +``` js +const renderer = createRenderer({ + cache: { + get: (key, cb) => { + redisClient.get(key, (err, res) => { + // handle error if any + cb(res) + }) + }, + set: (key, val) => { + redisClient.set(key, val) + } + } +}) +``` + ## Component-Level Caching You can easily cache components during SSR by implementing the `serverCacheKey` function: