Skip to content

Conversation

@Oxyjun
Copy link
Contributor

@Oxyjun Oxyjun commented Nov 26, 2024

Summary

  1. Adding DurableObject base class chapter, and listing its methods, including previously missing fetch and alarm.
  2. Adding cross-references between the new DurableObject base class chapter and Best Practices/Use WebSockets/
  3. Adding "Extended methods" heading to "Best practices/Using WebSockets" chapter. This section contains:
    • serializeAttachment
    • deserializeAttachment

Screenshots (optional)

Documentation checklist

  • The documentation style guide has been adhered to.
  • If a larger change - such as adding a new page- an issue has been opened in relation to any incorrect or out of date information that this PR fixes.
  • Files which have changed name or location have been allocated redirects.

@Oxyjun Oxyjun requested review from a team, elithrar, joshthoward and vy-ton as code owners November 26, 2024 17:26
@github-actions github-actions bot added size/s product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ labels Nov 26, 2024
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 26, 2024

Deploying cloudflare-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0ada43d
Status: ✅  Deploy successful!
Preview URL: https://8053b844.cloudflare-docs-7ou.pages.dev
Branch Preview URL: https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev

View logs

@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 2024

Files with changes (up to 15)

Original Link Updated Link
https://developers.cloudflare.com/durable-objects/api/base/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/api/base/
https://developers.cloudflare.com/durable-objects/best-practices/websockets/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/best-practices/websockets/
https://developers.cloudflare.com/durable-objects/api/state/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/api/state/
https://developers.cloudflare.com/durable-objects/api/alarms/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/api/alarms/
https://developers.cloudflare.com/durable-objects/api/id/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/api/id/
https://developers.cloudflare.com/durable-objects/api/namespace/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/api/namespace/
https://developers.cloudflare.com/durable-objects/api/sql-storage/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/api/sql-storage/
https://developers.cloudflare.com/durable-objects/api/storage-api/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/api/storage-api/
https://developers.cloudflare.com/durable-objects/api/stub/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/api/stub/
https://developers.cloudflare.com/durable-objects/api/webgpu/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/api/webgpu/
https://developers.cloudflare.com/durable-objects/api/workers-rs/ https://jun-do-base-object-cleanup.cloudflare-docs-7ou.pages.dev/durable-objects/api/workers-rs/


- <code> serializeAttachment(value <Type text="any" />)</code>: <Type text="void" />

- Keeps a copy of `value` in memory (not on disk) to survive hibernation. The value can be any type supported by the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), which is true of most types.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeps a copy of value in memory (not on disk)
@MellowYarker does a user need to worry about the case where the runtime crashes and potentially loses the in-memory copy? Does this count against the memory consumed by the Durable Object?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does a user need to worry about the case where the runtime crashes and potentially loses the in-memory copy

Yes, this will not survive a "hard" eviction. The only way this survives eviction is if we do a "soft" eviction (no requests for 10 seconds).

Does this count against the memory consumed by the Durable Object?

Not when the DO is hibernating. When the DO is awake and the WebSocket is in memory (it was just created, or received a message, or was brought back in via state.getWebSockets() it does contribute (because it lives in the isolate).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Oxyjun I would add that

Keeps a copy of value associated with the WebSocket to survive hibernation. The value can be any type supported by the structured clone algorithm, which is true of most types. If the value needs to be durable please use DurableObjectStorage (hyperlink the Durable Object storage reference)

@github-actions github-actions bot added size/m and removed size/s labels Dec 4, 2024
@github-actions github-actions bot added size/s and removed size/m labels Dec 4, 2024
@github-actions github-actions bot added size/m and removed size/s labels Dec 4, 2024
@Oxyjun Oxyjun enabled auto-merge (squash) December 4, 2024 14:55
@Oxyjun Oxyjun disabled auto-merge December 4, 2024 14:55
Co-authored-by: marciocloudflare <[email protected]>
@Oxyjun Oxyjun enabled auto-merge (squash) December 4, 2024 15:09
@Oxyjun Oxyjun merged commit 7fe83c9 into production Dec 4, 2024
12 checks passed
@Oxyjun Oxyjun deleted the jun/do/base-object-cleanup branch December 4, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants