开发者

Recommended Way to Control Making HTTP requests?

开发者 https://www.devze.com 2022-12-11 09:56 出处:网络
Hypothetically, if the user clicks \"save,save,save,save\" a bunch of times on a text file, making single character changes at a time and managing to resave 5 times before the first save is processed,

Hypothetically, if the user clicks "save,save,save,save" a bunch of times on a text file, making single character changes at a time and managing to resave 5 times before the first save is processed, what is best practice in that situation? Assuming we don't have a "batch process" optio开发者_C百科n... Or maybe they push save,save,save,save on 4 files one after the next before they've all been processed.

Should you queue up the requests and process them one at a time? Or should you just let it happen and it will work itself out somehow?

Thanks!


We usually send down a GUID in the page when a form is initialized, and send it along on the save request. The server checks a shared short-term memory cache- if it's a miss, we store the GUID and process the save, if it's a hit, we fail as a dupe request. This allows one save per page load (unless you do something to reinit the GUID on a successful save).


If you make your save operation light enough, it shouldn't matter how many times the user hits save. The amount of traffic a single user can generate is usually quite light compared to the load of thousands of users.

I'd suggest watching the HTTP traffic when you compose a Gmail message or work in Google docs. Both are very chatty, and frequently send updates back to the server.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号