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条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题