A non-locking in-process ASP.NET session state store

后端 未结 5 1503
挽巷
挽巷 2020-12-06 05:34

I\'m using ASP.NET\'s in-process session state store. It locks access to a session exclusively, and which means concurrent requests to the same session are served sequential

5条回答
  •  我在风中等你
    2020-12-06 06:01

    If you are only reading from the session on a given page you could use the Page directive:

    <%@ Page EnableSessionState="ReadOnly" %>
    

    to indicate the readonly nature and remove the exclusive write lock which will allow concurrent requests to this page from the same session.

    As internally a ReaderWriter lock is used a reader lock will block a writer lock but a reader lock won't block reader lock. Writer lock will block all reader and writer lock.

    If you need to both read and write from the same page to the session I think that what you've already found as information is more than sufficient. Just a remark about replacing the Session with Cache: while session is reliable, cache is not meaning that if you put something into the cache you are not guaranteed to retrieve it back. The ASP.NET could decide to evict the cache under some circumstances like low memory pressure so you always need to check if an item exists in the cache before accessing it.

提交回复
热议问题