https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • t

    Tobias Lins

    12/19/2020, 9:18 PM
    hehe enjoy
  • t

    Till

    12/29/2020, 3:10 AM
    What are the limits of DO?
  • t

    Till

    12/29/2020, 3:10 AM
    How many objects can I have in total?
  • t

    Till

    12/29/2020, 3:10 AM
    Are there any read/write costs?
  • c

    catgirl

    12/29/2020, 4:17 AM
    300MiB per account
  • c

    catgirl

    12/29/2020, 4:17 AM
    the number of objects isn't metered as far as im aware
  • c

    catgirl

    12/29/2020, 4:18 AM
    nor are there read/write costs to the user for now
  • c

    catgirl

    12/29/2020, 4:18 AM
    https://developers.cloudflare.com/workers/learning/using-durable-objects#limitations-during-the-beta
  • c

    catgirl

    12/29/2020, 4:21 AM
    I got this email from @User
  • c

    catgirl

    12/29/2020, 4:21 AM
    says more about the limits
  • t

    Till

    12/29/2020, 7:24 AM
    Thanks!
  • k

    kenton

    12/29/2020, 3:08 PM
    those limits are for the early beta only. Eventually there will be effectively no limit on the quantity of data or number of objects.
  • k

    kenton

    12/29/2020, 3:08 PM
    I mean, the 300MiB storage limit is temporary
  • t

    Till

    12/29/2020, 7:17 PM
    I'm finally able to dedicate some time to the beta. Stoked about it.
  • t

    Till

    12/29/2020, 7:17 PM
  • t

    Till

    12/29/2020, 7:19 PM
    I've got a question regarding the
    fetch()
    method on the durable object class. Does it have to be a
    Request
    or can I just pass any kind of string/identifier? I'm confused by the docs.
  • t

    Till

    12/29/2020, 8:06 PM
    Also, can
    this.storage.put();
    store objects, or only text?
  • c

    connyay

    12/29/2020, 8:11 PM
    Docs call out: > The value can be any type supported by the structured clone algorithm, which is true of most types. https://developers.cloudflare.com/workers/runtime-apis/durable-objects#methods https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
  • k

    kenton

    12/29/2020, 8:27 PM
    fetch()
    is explicitly HTTP-based. On the calling side it has exactly the signature of the global
    fetch()
    function. On the receiving end, the parameter is always a
    Request
    and it must return a
    Response
    .
  • k

    kenton

    12/29/2020, 8:28 PM
    As @User pointed out,
    storage.put()
    supports any value that is supported by structured clone. That should be a strict superset of things that you could JSON-stringify, FWIW.
  • k

    kenton

    12/29/2020, 8:28 PM
    (we use V8 serialization for the actual storage)
  • t

    Till

    12/29/2020, 8:58 PM
    Very helpful guys!
  • t

    Till

    12/29/2020, 8:59 PM
    Copy code
    export class Plugin {
    
      constructor(state, env) {
        this.storage = state.storage
      }
    
      async initialize() {
        let stored = await this.storage.get('info')
    
        this.value = stored || null
      }
    
      async fetch(request) {
        if (! this.shouldInitialize) {
          this.shouldInitialize = this.initialize()
        }
    
        await this.shouldInitialize
    
        let currentValue = this.value
    
        if (request.method === 'POST') {
          currentValue = this.value = await request.json()
    
          await this.storage.put('info', this.value)
        }
    
        return new Response(JSON.stringify(currentValue), {
          headers: { 'Content-Type': 'application/json; charset=utf-8' },
        })
      }
    }
  • t

    Till

    12/29/2020, 9:00 PM
    This seems to be good.
  • t

    Till

    12/29/2020, 9:00 PM
    Now, I'm running a Worker Site. Are there any examples out there where to place the
    .mjs
    file as well as the
    metadata.json
    and
    calling-worker.json
    ?
  • t

    Till

    12/29/2020, 9:01 PM
    I couldn't find anything, except https://github.com/cloudflare/workers-chat-demo, which isn't Worker Sites specific.
  • k

    kenton

    12/29/2020, 9:03 PM
    unfortunately, wrangler doesn't yet support modules nor durable objects... and Workers Sites is entirely a feature of wrangler.
  • k

    kenton

    12/29/2020, 9:03 PM
    so at the moment you would have to disassemble your Workers Site into the raw API calls that Wrangler makes, and make those yourself
  • k

    kenton

    12/29/2020, 9:04 PM
    so that you could use them together with durable objects
  • k

    kenton

    12/29/2020, 9:04 PM
    this is something we intend to fix before open beta
1...456...567Latest