问题描述
我有从数据库访问进程列表并选择一个随机的过程,使得用户可以分析的MVC网站。他可以aprove与否的过程,并自动接收另一个。
I have a MVC web site that access a process list from database and select a "random" process so that the user can analyze. He can aprove or not that process and automatically receive another.
问题是多个用户将同时做好过程,我需要阻止那些已经在审查过程。
The problem is several users will do the process simultaneously and I need to block those processes that are already under review.
我不能这样做数据库的一面,所以必须是一个应用解决方案,完全不可见的用户...
I can´t do that on database side, so must be an application solution and completely invisible to users...
我该如何解决这个问题?
How can I solve that problem?
---编辑
的一种情况是:用户获取进程(进程已锁定),比他忘记打开或关闭浏览器。
所以,我需要以某种方式解锁过程。
One scenario will be : User get a process (the process is locked), than he "forgets" open or "closes" the browser.So I need to unlock that process somehow.
一些想法我有:
-
使用MSMQ(这是可能放回当用户忘记完成任务的过程?)
Using MSMQ (Is that possible to put back a process when the user "forget" to finish the task?)
使用我的web应用程序的静态ConcurrentBag保持对审核ID列表。 (威尔IIS回收杀死名单?)
Using a static ConcurrentBag on my webapp to keep the list of ids on review. (Will IIS recycle kill that list?)
感谢
推荐答案
如果数据库表是不是一种选择,你可以创建一个内存缓存,可存储的Id的其中正在审查。每当有人开始进行审查,检查内存高速缓存ID是否进行审查存在有或没有。如果不存在,添加新的ID到内存缓存。(你可以存储的ID在内存缓存列表)。
If database table is not an option, you may create an in-memory cache where you can store the Id's which are under review. Every time someone starts a review, check the memory cache to see whether the Id to be reviewed exists there or not. If not exists, Add the new id to the memory cache.(You may store a List of Ids in the memory cache).
您可以使用的类来实现这一点。
You can use the MemoryCache class to achieve this.
请记住,这是在内存中。所以,你的应用程序池的复位可以清除内存。此外,当你在未来有一个以上的服务器,这可能无法正常工作(麻烦共享跨服务器的高速缓存!)。在这种情况下,你需要一个集中的地方来保存这些信息。我的建议是在你的SQL Server中的数据库表。
Remember, this is in-memory. So your App pool reset can clear the memory. Also when you have more than one server in future, this might not work ( trouble sharing cache across servers!). In that case, you need a centralized place to keep this information. My recommendation is a db table in your sql server.
这篇关于并发访问对MVC的.NET数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!