What's the best way for the client app to immediately react to an update in the database?

前端 未结 4 487
Happy的楠姐
Happy的楠姐 2021-02-05 23:24

What is the best way to program an immediate reaction to an update to data in a database?

The simplest method I could think of offhand is a thread that checks the databa

4条回答
  •  忘了有多久
    2021-02-06 00:04

    I figure there must be some way, after all, web application like gmail seem to update my inbox almost immediately after a new email was sent to me. Surely my client isn't continually checking for updates all the time. I think the way they do this is with AJAX, but how AJAX can behave like a remote function call I don't know. I'd be curious to know how gmail does this, but what I'd most like to know is how to do this in the general case with a database.

    Take a peek with wireshark sometime... there's some google traffic going on there quite regularly, it appears.

    Depending on your DB, triggers might help. An app I wrote relies on triggers but I use a polling mechanism to actually 'know' that something has changed. Unless you can communicate the change out of the DB, some polling mechanism is necessary, I would say.

    Just my two cents.

提交回复
热议问题