You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/durable-objects/api/namespace.mdx
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ export default {
71
71
72
72
### `idFromName`
73
73
74
-
`idFromName` creates a [`DurableObjectId`](/durable-objects/api/id) which refers to an individual instance of the Durable Object class from a particular name.
74
+
`idFromName` creates a unique [`DurableObjectId`](/durable-objects/api/id) which refers to an individual instance of the Durable Object class. Named Durable Object instances are the most common method of referring to Durable Object instances.
`newUniqueId` creates a `DurableObjectId` which refers to an individual instance of the Durable Object class. When using `newUniqueId`, you need to store the ID as a string in order to refer to the same Durable Object again in the future. For example, the ID can be stored in Workers KV, another Durable Object instance, or in a cookie in the user's browser.
91
+
`newUniqueId` creates a randomly generated and unique [`DurableObjectId`](/durable-objects/api/id) which refers to an individual instance of the Durable Object class. IDs created using `newUniqueId`, will need to be stored as a string in order to refer to the same Durable Object again in the future. For example, the ID can be stored in Workers KV, another Durable Object instance, or in a cookie in the user's browser.
Copy file name to clipboardExpand all lines: src/content/docs/durable-objects/get-started/tutorial-with-sql-api.mdx
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -185,7 +185,7 @@ export default {
185
185
In the code above, you have:
186
186
187
187
1. Exported your Worker's main event handlers, such as the `fetch()` handler for receiving HTTP requests.
188
-
2. Passed `env` into the `fetch()` handler. Bindings are delivered as a property of the environment object passed as the second parameter when an event handler or class constructor is invoked. By calling the `idFromName()` function on the binding, you use a string-derived object ID. You can also ask the system to [generate random unique IDs](/durable-objects/best-practices/access-durable-objects-from-a-worker/#generate-ids-randomly). System-generated unique IDs have better performance characteristics, but require you to store the ID somewhere to access the Object again later.
188
+
2. Passed `env` into the `fetch()` handler. Bindings are delivered as a property of the environment object passed as the second parameter when an event handler or class constructor is invoked. By calling the `idFromName()` function on the binding, you use a string-derived object ID. You can also ask the system to [generate random unique IDs](/durable-objects/api/namespace/#newuniqueid). System-generated unique IDs have better performance characteristics, but require you to store the ID somewhere to access the Object again later.
189
189
3. Derived an object ID from the URL path. `MY_DURABLE_OBJECT.idFromName()` always returns the same ID when given the same string as input (and called on the same class), but never the same ID for two different strings (or for different classes). In this case, you are creating a new object for each unique path.
190
190
4. Constructed the stub for the Durable Object using the ID. A stub is a client object used to send messages to the Durable Object.
191
191
5. Called a Durable Object by invoking a RPC method, `sayHello()`, on the Durable Object, which returns a `Hello, World!` string greeting.
@@ -258,7 +258,6 @@ By finishing this tutorial, you have successfully created, tested and deployed a
258
258
259
259
### Related resources
260
260
261
-
-[Access a Durable Object from a Worker](/durable-objects/best-practices/access-durable-objects-from-a-worker/)
Copy file name to clipboardExpand all lines: src/content/docs/durable-objects/reference/websockets.mdx
+6-13Lines changed: 6 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@ pcx_content_type: concept
3
3
title: Durable Objects with WebSockets
4
4
sidebar:
5
5
order: 3
6
-
7
6
---
8
7
9
8
[WebSockets](/durable-objects/api/websockets/) allow real time communication between a client and server. Both Cloudflare Durable Objects and Workers can act as WebSocket endpoints – either as a client or as a server.
@@ -14,16 +13,14 @@ Durable Objects provide a single-point-of-coordination for [Cloudflare Workers](
14
13
15
14
While there are other use cases for using Workers exclusively with WebSockets, WebSockets are most useful when combined with Durable Objects.
16
15
17
-
When a client connects to your application using a WebSocket, you need a way for server-generated messages to be sent using the existing socket connection. Multiple clients can establish a WebSocket connection with a specific Durable Object addressed by its [unique ID](/durable-objects/best-practices/access-durable-objects-from-a-worker/#1-create-durable-object-ids). The Durable Object can then send messages to each client over the WebSocket connection.
16
+
When a client connects to your application using a WebSocket, you need a way for server-generated messages to be sent using the existing socket connection. Multiple clients can establish a WebSocket connection with a specific Durable Object addressed by its unique ID. The Durable Object can then send messages to each client over the WebSocket connection.
18
17
19
18
Durable Objects can use the web standard APIs described in [WebSockets API](/durable-objects/api/websockets/). Refer to [Cloudflare Edge Chat Demo](https://github.com/cloudflare/workers-chat-demo) for an example of using Durable Objects with WebSockets.
20
19
21
20
:::caution[WebSockets disconnection]
22
21
23
-
24
22
Code updates will disconnect all WebSockets. If you deploy a new version of a Worker, every Durable Object is restarted. Any connections to old Durable Objects will be disconnected.
25
23
26
-
27
24
:::
28
25
29
26
## WebSocket Hibernation
@@ -32,19 +29,17 @@ The WebSocket Hibernation API allows a Durable Object that is not currently runn
32
29
33
30
:::note
34
31
35
-
36
32
Hibernation is only supported when a Durable Object acts as a WebSocket server. Outgoing WebSockets cannot be hibernated as of now.
37
33
38
-
39
34
:::
40
35
41
36
A Durable Object with WebSockets created via the Hibernation API will not incur billable [Duration (GB-s) charges](/durable-objects/platform/pricing/) during periods of inactivity, unlike Durable Objects using the [regular WebSockets API](/workers/runtime-apis/websockets/).
42
37
43
38
The WebSocket Hibernation API includes:
44
39
45
-
* Cloudflare-specific extensions to the web standard WebSocket API.
46
-
* Related methods on the [`state`](/durable-objects/api/websockets/#state-methods) of the Durable Object.
47
-
*[Handler methods](/durable-objects/api/websockets/#handler-methods) that a Durable Object can implement for processing WebSocket events.
40
+
- Cloudflare-specific extensions to the web standard WebSocket API.
41
+
- Related methods on the [`state`](/durable-objects/api/websockets/#state-methods) of the Durable Object.
42
+
-[Handler methods](/durable-objects/api/websockets/#handler-methods) that a Durable Object can implement for processing WebSocket events.
48
43
49
44
The WebSocket Hibernation API enables you to terminate (not proxy) WebSocket connections within a Durable Object, and push messages to all connected clients based on state stored within the [Storage API](/durable-objects/api/storage-api/), HTTP fetches to external services, and/or data stored in [R2](/r2/) and [Workers KV](/kv/api/).
50
45
@@ -54,16 +49,14 @@ If an event occurs for a hibernated Durable Object's corresponding handler metho
54
49
55
50
:::caution[Support for local development]
56
51
57
-
58
52
Prior to `[email protected]` and Miniflare `v3.20231016.0`, WebSockets did not hibernate when using local development environments such as `wrangler dev` or Miniflare.
59
53
60
54
If you are using older versions, note that while hibernatable WebSocket events such as [`webSocketMessage()`](/durable-objects/api/websockets/#websocketmessage) will still be delivered, the Durable Object will never be evicted from memory.
61
55
62
-
63
56
:::
64
57
65
-
***
58
+
---
66
59
67
60
## Related resources
68
61
69
-
* Refer to [Build a WebSocket server with WebSocket Hibernation](/durable-objects/examples/websocket-hibernation-server/) to learn more about building a WebSocket server using WebSocket Hibernation on Durable Objects and Workers.
62
+
- Refer to [Build a WebSocket server with WebSocket Hibernation](/durable-objects/examples/websocket-hibernation-server/) to learn more about building a WebSocket server using WebSocket Hibernation on Durable Objects and Workers.
Copy file name to clipboardExpand all lines: src/content/docs/workers/configuration/versions-and-deployments/gradual-deployments.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -205,7 +205,7 @@ When you create a new gradual deployment for a Durable Object Worker, each Durab
205
205
206
206
### Example
207
207
208
-
This example assumes that you have previously created 3 Durable Objects and [derived their IDs from the names](/durable-objects/best-practices/access-durable-objects-from-a-worker/#derive-ids-from-names) "foo", "bar" and "baz".
208
+
This example assumes that you have previously created 3 Durable Objects and [derived their IDs from the names](/durable-objects/api/namespace/#idfromname) "foo", "bar" and "baz".
209
209
210
210
Your Worker is currently on a version that we will call version "A" and you want to gradually deploy a new version "B" of your Worker.
0 commit comments