简体   繁体   English

跨 Web api 请求(用户会话)共享和更新静态集合

[英]Share and update the static collection across the web api requests (user sessions)

I need each user requestid to store in static collection object.我需要每个用户 requestid 存储在静态集合对象中。 on each next request need to check if same user request exist then process some specific task using it.在每个下一个请求中需要检查是否存在相同的用户请求,然后使用它处理一些特定的任务。

So, to achieve this, I am thinking to preserve static list object.所以,为了实现这一点,我想保留static list对象。 but as in web requests it will not give me correct value or update collection correctly because of static object in web.但在 web 请求中,由于 web.xml 中的静态对象,它不会给我正确的值或正确更新集合。

can you please share me what is the ideal approach here, I should use or way to handle static collection object in web (while updating collection or retrieving collection).能否请您分享一下这里的理想方法是什么,我应该使用或方法来处理 web 中的静态集合对象(在更新集合或检索集合时)。

If you want to build it yourself then at least use a concurrent collection:http://msdn.microsoft.com/en-us/library/dd997373(v=vs.110).aspx since you will be accessing the collection from multiple threads.如果您想自己构建它,那么至少使用并发集合:http ://msdn.microsoft.com/en-us/library/dd997373(v=vs.110).aspx因为您将从多个访问该集合线程。

Otherwise I suggest using MemoryCache, a thread-safe built-in mechanism.否则我建议使用 MemoryCache,一种线程安全的内置机制。 See http://msdn.microsoft.com/en-us/library/ff477235.aspx请参阅http://msdn.microsoft.com/en-us/library/ff477235.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM