cloudflare-docs
cloudflare-docs copied to clipboard
Durable Object Storage pattern should mention cost considerations for read pattern docs recommended
Which Cloudflare product does this pertain to?
Workers
Existing documentation URL(s)
- https://developers.cloudflare.com/workers/learning/using-durable-objects/#in-memory-state-in-a-durable-object
Section that requires update
Built-in caching The Durable Object’s storage has a built-in in-memory cache of its own – if you get() a value that was read or written recently, the result will be instantly returned from cache. Instead of writing initialization code like above, you could get("value") whenever you need it, and rely on the built-in cache to make this fast. Refer to the Counter example below for an example of this approach.
What needs to change?
recommending that users read for every request will be costly now that the pricing for "durable objects storage api" is based number of 4KB bytes read from disk - regardless of cached state:
https://developers.cloudflare.com/workers/platform/pricing/#durable-objects-storage-api
Requests that hit the Durable Objects in-memory cache or that use the multi-key versions of get/put/delete methods are billed the same as if they were a normal, individual request for each key.
How should it change?
In the next paragraph it says:
However, in applications with more complex state, explicitly storing state in your Object may be easier than making storage API calls on every access
Include a note that cost is based on number reads as well regardless of cached state - and refer to the pricing section?
Additional information
No response