douhu4091 2018-02-18 07:09
浏览 5
已采纳

不允许同时页面查看Laravel

I have an app for self-delivery centers, where several operators (users) can process their common list of orders. But I need to restrict them from processing the same order simultaneously.

I.e. when order is viewed by some user and second user gets into that order too, processing buttons must not be shown for the second user.

How can I do this in Laravel 5.5?

  • 写回答

2条回答 默认 最新

  • dongqi9125 2018-02-18 08:46
    关注

    While there are many possible ways to handle a problem like this, adding a cache entry for that order to indicate that it is being processed currently might do the trick.

    There are some caveats, but the following logic might work:

    1. When user loads the order, place an entry in cache for this order, perhaps cache key "order_in_progress:1234"
    2. Set a time to live on the cache key for something reasonable, according to how long it takes to process an order, but perhaps 5 minutes (it should go back to being able to be processed if it doesn't get completed).
    3. The cache value should probably be the user which is attempting to process the order so that a page refresh would still allow the same user to load the page again and edit it.
    4. Using the cache key and the time to live value you could even show the user how much time is remaining to process the order before it can be processed by someone else (this is an extra).
    5. If multiple users load the unprocessed orders page at the same time they might be able to click the link which could result in a page being loaded again, but the key is to check if there is a cache entry for this order number in cache indicating it is already being processed. If a key exists, it is still visible but no actions can be taken until the first user succeeds or times out.
    6. Once the order is processed, as part of cleanup you could delete that cache key; Or, you could just let it expire since processed orders wouldn't appear in that screen anyway since they aren't relevant.

    This would likely satisfy your requirements and probably a lot more. Honestly, given your requirements it sounds like there could be more things you haven't considered but feel free to ask for further clarification.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?