Skip to content

Commit 469fbc6

Browse files
docs: update caching guide
1 parent 09a03ce commit 469fbc6

File tree

7 files changed

+1163
-1250
lines changed

7 files changed

+1163
-1250
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ And send queries in your template:
4646

4747
```vue
4848
<script setup lang="ts">
49-
const { data, pending, refresh, error } = await useKql({
49+
const { data, refresh, error, status, clear } = await useKql({
5050
query: 'site'
5151
})
5252
</script>

docs/api/use-kql.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,37 @@ type UseKqlOptions<T> = AsyncDataOptions<T> & Pick<
5151
- `data`: the result of the asynchronous function that is passed in.
5252
- `refresh`/`execute`: a function that can be used to refresh the data returned by the `handler` function.
5353
- `error`: an error object if the data fetching failed.
54-
- `status`: a string indicating the status of the data request (`"idle"`, `"pending"`, `"success"`, `"error"`).
54+
- `status`: a string indicating the status of the data request (`'idle'`, `'pending'`, `'success'`, `'error'`).
5555
- `clear`: a function which will set `data` to `undefined`, set `error` to `null`, set `status` to `'idle'`, and mark any currently pending requests as cancelled.
5656
5757
By default, Nuxt waits until a `refresh` is finished before it can be executed again.
5858
59+
## Caching
60+
61+
By default, a [unique key is generated](/guide/caching) based in input parameters for each request to ensure that data fetching can be properly de-duplicated across requests. To disable caching, set the `cache` option to `false`:
62+
63+
```ts
64+
const { data } = await useKql({ query: 'site' }, {
65+
cache: false
66+
})
67+
```
68+
69+
Clear the cache for a specific query by calling the `clear` function. This will remove the cached data for the query and allow the next request to fetch the data from the server:
70+
71+
```ts
72+
const { data, refresh, clear } = await useKql({ query: 'site' })
73+
74+
async function invalidateAndRefresh() {
75+
clear()
76+
await refresh()
77+
}
78+
```
79+
5980
## Example
6081

6182
```vue
6283
<script setup lang="ts">
63-
const { data, pending, error, refresh } = await useKql({
84+
const { data, refresh, error, status, clear } = await useKql({
6485
query: 'site',
6586
select: ['title', 'children']
6687
})

docs/config/caching.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ const { data } = await useKql(
1818
)
1919
```
2020

21+
## Clearing the Cache
22+
23+
```ts
24+
const { data, refresh, clear } = await useKql({ query: 'site' })
25+
26+
async function invalidateAndRefresh() {
27+
clear()
28+
await refresh()
29+
}
30+
```
31+
2132
## Server-Side Caching
2233

2334
Nuxt KQL lets you opt in to server-side caching of query responses. It does so by utilizing the [cache API](https://nitro.unjs.io/guide/cache) of Nuxt's underlying server engine, [Nitro](https://nitro.unjs.io). Query responses are cached in-memory by default, but you can use any storage mountpoints supported by Nitro. The full list of built-in storage mountpoints can be found in the [unstorage documentation](https://unstorage.unjs.io).

docs/guide/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Use the globally available [`useKql`](/api/use-kql) composable to send queries:
6262

6363
```vue
6464
<script setup lang="ts">
65-
const { data, pending, refresh, error } = await useKql({
65+
const { data, refresh, error, status, clear } = await useKql({
6666
query: 'site',
6767
select: {
6868
title: true,

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"preview": "vitepress preview"
99
},
1010
"devDependencies": {
11-
"vitepress": "^1.3.2"
11+
"vitepress": "^1.3.4"
1212
}
1313
}

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nuxt-kql",
33
"type": "module",
44
"version": "1.5.0",
5-
"packageManager": "pnpm@9.6.0",
5+
"packageManager": "pnpm@9.9.0",
66
"description": "Kirby's Query Language API for Nuxt",
77
"author": "Johann Schopplich <[email protected]>",
88
"license": "MIT",
@@ -49,8 +49,8 @@
4949
"release": "bumpp"
5050
},
5151
"dependencies": {
52-
"@nuxt/kit": "^3.12.4",
53-
"@vueuse/core": "^10.11.0",
52+
"@nuxt/kit": "^3.13.0",
53+
"@vueuse/core": "^11.0.3",
5454
"defu": "^6.1.4",
5555
"kirby-types": "^0.7.1",
5656
"ofetch": "^1.3.4",
@@ -61,14 +61,14 @@
6161
"uint8array-extras": "^1.4.0"
6262
},
6363
"devDependencies": {
64-
"@nuxt/eslint-config": "^0.5.0",
65-
"@nuxt/module-builder": "^0.8.1",
66-
"@nuxt/test-utils": "^3.14.0",
67-
"@types/node": "^20.14.14",
68-
"bumpp": "^9.4.2",
64+
"@nuxt/eslint-config": "^0.5.4",
65+
"@nuxt/module-builder": "^0.8.3",
66+
"@nuxt/test-utils": "^3.14.1",
67+
"@types/node": "^20.16.2",
68+
"bumpp": "^9.5.2",
6969
"destr": "^2.0.3",
70-
"eslint": "^9.8.0",
71-
"nuxt": "^3.12.4",
70+
"eslint": "^9.9.1",
71+
"nuxt": "^3.13.0",
7272
"typescript": "^5.5.4",
7373
"vitest": "^2.0.5"
7474
}

0 commit comments

Comments
 (0)