Skip to content

Commit

Permalink
Rename createCloudflareKVSessionStorage
Browse files Browse the repository at this point in the history
Use "Cloudflare Workers KV" instead of "Cloudflare KV" everywhere.
  • Loading branch information
mjackson committed Mar 29, 2022
1 parent 21ec837 commit 4d64a8c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
10 changes: 5 additions & 5 deletions docs/api/remix.md
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,7 @@ Remix comes with several pre-built session storage options for common scenarios,
- `createCookieSessionStorage`
- `createMemorySessionStorage`
- `createFileSessionStorage` (node)
- `createCloudflareKVSessionStorage` (cloudflare-workers)
- `createWorkersKVSessionStorage` (Cloudflare Workers)
- `createArcTableSessionStorage` (architect, Amazon DynamoDB)
- custom storage with `createSessionStorage`

Expand Down Expand Up @@ -2271,17 +2271,17 @@ const { getSession, commitSession, destroySession } =
export { getSession, commitSession, destroySession };
```

### `createCloudflareKVSessionStorage` (cloudflare-workers)
### `createWorkersKVSessionStorage` (Cloudflare Workers)

For [Cloudflare KV](https://developers.cloudflare.com/workers/learning/how-kv-works) backed sessions, use `createCloudflareKVSessionStorage()`.
For [Cloudflare Workers KV](https://developers.cloudflare.com/workers/learning/how-kv-works) backed sessions, use `createWorkersKVSessionStorage()`.

The advantage of KV backed sessions is that only the session ID is stored in the cookie while the rest of the data is stored in a globally replicated, low-latency data store with exceptionally high read volumes with low-latency.

```js
// app/sessions.server.js
import {
createCookie,
createCloudflareKVSessionStorage,
createWorkersKVSessionStorage,
} from "remix";

// In this example the Cookie is created separately.
Expand All @@ -2291,7 +2291,7 @@ const sessionCookie = createCookie("__session", {
});

const { getSession, commitSession, destroySession } =
createCloudflareKVSessionStorage({
createWorkersKVSessionStorage({
// The KV Namespace where you want to store sessions
kv: YOUR_NAMESPACE,
cookie: sessionCookie,
Expand Down
5 changes: 4 additions & 1 deletion packages/remix-cloudflare-pages/magicExports/remix.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Re-export everything from this package that is available in `remix`.

export { createCloudflareKVSessionStorage } from "@remix-run/cloudflare";
export {
createWorkersKVSessionStorage,
createCloudflareKVSessionStorage,
} from "@remix-run/cloudflare";
5 changes: 4 additions & 1 deletion packages/remix-cloudflare-workers/magicExports/remix.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Re-export everything from this package that is available in `remix`.

export { createCloudflareKVSessionStorage } from "@remix-run/cloudflare";
export {
createWorkersKVSessionStorage,
createCloudflareKVSessionStorage,
} from "@remix-run/cloudflare";
6 changes: 5 additions & 1 deletion packages/remix-cloudflare/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import "./globals";

export { createCloudflareKVSessionStorage } from "./sessions/cloudflareKVSessionStorage";
export {
createWorkersKVSessionStorage,
// TODO: Deprecate createCloudflareKVSessionStorage
createWorkersKVSessionStorage as createCloudflareKVSessionStorage,
} from "./sessions/workersKVStorage";

export {
createCookie,
Expand Down
1 change: 1 addition & 0 deletions packages/remix-cloudflare/magicExports/remix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Re-export everything from this package that is available in `remix`.

export {
createWorkersKVSessionStorage,
createCloudflareKVSessionStorage,
createCookie,
createSessionStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {

import { createSessionStorage } from "../implementations";

interface CloudflareKVSessionStorageOptions {
interface WorkersKVSessionStorageOptions {
/**
* The Cookie used to store the session id on the client, or options used
* to automatically create one.
Expand All @@ -24,10 +24,10 @@ interface CloudflareKVSessionStorageOptions {
* The advantage of using this instead of cookie session storage is that
* KV Store may contain much more data than cookies.
*/
export function createCloudflareKVSessionStorage({
export function createWorkersKVSessionStorage({
cookie,
kv,
}: CloudflareKVSessionStorageOptions): SessionStorage {
}: WorkersKVSessionStorageOptions): SessionStorage {
return createSessionStorage({
cookie,
async createData(data, expires) {
Expand Down

0 comments on commit 4d64a8c

Please sign in to comment.