Example: Caching a response from an external API
When your app calls an external API, you don’t always need to fetch fresh data every time. With the KV Store, you can cache the response and set a TTL so it clears itself after a certain period of time.get-users.server.ts
API
get(key: string): Promise<{ value: string } | null>
null if the key does not exist.
Parameters
string
required
The key to get the value of.
set(key: string, value: string, options?: { ttlInSeconds?: number }): Promise<void>
Parameters
string
required
The key to set the value of.
string
required
The value to set for the key.
{ ttlInSeconds?: number }
The options for the key. Currently, the only option is
ttlInSeconds which is the number of
seconds after which the key will be deleted.delete(key: string): Promise<void>
Parameters
string
required
The key to delete.