Skip to content

Commit

Permalink
Add some docs about the cache invalidation strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudutour committed Sep 15, 2023
1 parent 9f41273 commit 84273a0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
6 changes: 5 additions & 1 deletion docs/utils-reference/react-hooks/useCachedPromise.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# `useCachedPromise`

Hook which wraps an asynchronous function or a function that returns a Promise and returns the [AsyncState](#asyncstate) corresponding to the execution of the function. The last value will be kept between command runs.
Hook which wraps an asynchronous function or a function that returns a Promise and returns the [AsyncState](#asyncstate) corresponding to the execution of the function.

It follows the `stale-while-revalidate` cache invalidation strategy popularized by [HTTP RFC 5861](https://tools.ietf.org/html/rfc5861). `useCachedPromise` first returns the data from cache (stale), then executes the promise (revalidate), and finally comes with the up-to-date data again.

The last value will be kept between command runs.

{% hint style="info" %}
The value needs to be JSON serializable.
Expand Down
6 changes: 5 additions & 1 deletion docs/utils-reference/react-hooks/useExec.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# `useExec`

Hook that executes a command and returns the [AsyncState](#asyncstate) corresponding to the execution of the command. The last value will be kept between command runs.
Hook that executes a command and returns the [AsyncState](#asyncstate) corresponding to the execution of the command.

It follows the `stale-while-revalidate` cache invalidation strategy popularized by [HTTP RFC 5861](https://tools.ietf.org/html/rfc5861). `useExec` first returns the data from cache (stale), then executes the command (revalidate), and finally comes with the up-to-date data again.

The last value will be kept between command runs.

## Signature

Expand Down
6 changes: 5 additions & 1 deletion docs/utils-reference/react-hooks/useFetch.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# `useFetch`

Hook which fetches the URL and returns the [AsyncState](#asyncstate) corresponding to the execution of the fetch. The last value will be kept between command runs.
Hook which fetches the URL and returns the [AsyncState](#asyncstate) corresponding to the execution of the fetch.

It follows the `stale-while-revalidate` cache invalidation strategy popularized by [HTTP RFC 5861](https://tools.ietf.org/html/rfc5861). `useFetch` first returns the data from cache (stale), then sends the request (revalidate), and finally comes with the up-to-date data again.

The last value will be kept between command runs.

## Signature

Expand Down
2 changes: 1 addition & 1 deletion docs/utils-reference/react-hooks/useSQL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `useSQL`

Hook which executes a query on a local SQL database and returns the [AsyncState](#asyncstate) corresponding to the execution of the query. The last value will be kept between command runs.
Hook which executes a query on a local SQL database and returns the [AsyncState](#asyncstate) corresponding to the execution of the query.

## Signature

Expand Down
13 changes: 1 addition & 12 deletions src/useSQL.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import {
showToast,
Toast,
List,
ActionPanel,
Action,
environment,
MenuBarExtra,
Icon,
open,
LaunchType,
} from "@raycast/api";
import { List, ActionPanel, Action, environment, MenuBarExtra, Icon, open, LaunchType } from "@raycast/api";
import { existsSync } from "node:fs";
import { copyFile, mkdir, writeFile } from "node:fs/promises";
import os from "node:os";
Expand Down

0 comments on commit 84273a0

Please sign in to comment.