缓存 vs 会话的优势 [英] Advantages of Cache vs Session

查看:27
本文介绍了缓存 vs 会话的优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在会话和缓存中存储数据表有什么区别?有什么优点和缺点?

What is the difference between storing a datatable in Session vs Cache? What are the advantages and disadvantages?

所以,如果它是一个简单的搜索页面,它在数据表中返回结果并将其绑定到网格视图.如果用户a"搜索和用户b"搜索,最好将其存储在会话中,因为每个用户很可能会得到不同的结果,或者我仍然可以将他们的每个搜索存储在缓存中还是没有意义,因为有只有一个缓存.我想基本上我想说的是缓存会被覆盖.

So, if it is a simple search page which returns result in a datatable and binds it to a gridview. If user 'a' searches and user 'b' searches, is it better to store it in Session since each user would most likely have different results or can I still store each of their searches in Cache or does that not make sense since there is only one cache. I guess basically what I am trying to say is that would the Cache be overwritten.

推荐答案

一个重要的区别是,缓存中的项目可以在指定的时间后过期(将从缓存中删除).放入会话的项目将保留在那里,直到会话结束.

One important difference is, that items in the cache can expire (will be removed from cache) after a specified amount of time. Items put into a session will stay there, until the session ends.

当可用内存量变小时,ASP.NET 还可以从缓存中删除项目.

ASP.NET can also remove items from cache when the amount of available memory gets small.

另一个区别:会话状态可以保持在外部(状态服务器、SQL 服务器)并在您的 Web 应用程序的多个实例之间共享(用于负载平衡).缓存不是这种情况.

Another difference: the session state can be kept external (state server, SQL server) and shared between several instances of your web app (for load balancing). This is not the case with the cache.

除了这些差异(正如其他人所指出的):会话是每个用户/会话,而缓存是每个应用程序.

Besides of these differences (as others have noted): session is per user/session while cache is per application.

这篇关于缓存 vs 会话的优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆