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 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)