ASP.NET中的会话,缓存和配置文件之间有什么区别 [英] what is difference between session, cache and profile in asp.net

查看:101
本文介绍了ASP.NET中的会话,缓存和配置文件之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们经常在asp.net Webform项目中使用会话,缓存和配置文件.我们经常在asp.net Webform项目中将数据存储在会话,缓存和配置文件中,但是我想知道何时应该在会话中存储数据,或者何时应该在缓存和配置文件中存储数据.缓存或配置文件的范围是什么?这两个会话还特定于会话的生存时间或特定于应用程序.

we often use session, cache and profile in asp.net webform project. we often store data in session, cache and profile in asp.net webform project but i like to know when we should store data in session or when we should store in cache and profile. what is the scope of cache or profile. this two also session specific life time or application specific.

假设如果我将任何数据存储在会话1的缓存或配置文件中,那么我是否可以从会话2访问该数据.只是用场景和我来指导我我们应该在会话,缓存和配置文件中存储数据的示例.谢谢

suppose if i store any data in cache or profile from session 1 then can i access that data from session2 or not. just guide me with scenario & example when we should store data in session, cache and profile. thanks

推荐答案

通常在要提高站点性能时使用cache:减少数据库调用,访问文件系统上的文件,调用外部服务等.

You use cache typically when you want to improve site performance: reduce database calls, accessing files on filesystem, calling external services, etc.

Scenario 1:假设有一个应用程序,该应用程序的页面列出了存储在数据库中的所有产品.用户需要产品列表过滤功能(例如在ebay或Amazon上).另外,与产品列表页面的使用频率相比,产品列表和产品功能的变化很少.

Scenario 1: Assume there is an application which has a page that lists all products stored in database. Users have need in product list filtering feature (like on ebay or amazon for example). Also it is known that list of products and product features are changing rarely comparing to frequency of product list page usage.

Solution 1:在这里您可以使用cache减少数据库调用.您将产品列表和产品功能放入cache,以在内存中执行过滤并避免冗余的数据库调用.每当产品列表或功能更改时,Cache应该无效.在内存消耗处理比性能获得便宜之前,这种解决方案应该可以.

Solution 1: Here you can use cache to reduce database calls. You put product list and product features to cache to perform filtering in memory and avoid redundant database calls. Cache should be invalidated whenever product list or feature changes. This solution should be OK until memory consumption handling is cheaper than gain in performance.

作为一个很好的资源,我建议阅读 ASP.NET缓存:技术和最佳做法 MSDN文章.

As a good resource I suggest reading the ASP.NET Caching: Techniques and Best Practices MSDN article.

profile中,您通常保存特定于特定用户的数据,并且该数据在用户每次登录系统时都将可用.

In profile you typically save data which is specific to concrete user and should be available at every time user logs into system.

Scenario 2:考虑您具有与Scenario 1中相同的应用程序,但是现在您需要为用户提供保存其过滤器首选项(喜欢的过滤器列表的种类)的功能.

Scenario 2: Consider you have the same application as in Scenario 1 but now you need to provide ability for users to save their filter preferences (kind of list of favourite filters).

Solution 2:您可以创建一种过滤状态类,并将其存储在用户profile中.这样一来,用户将不会再麻烦一次又一次地指定过滤器参数,并且每次用户登录时,这些首选项都将可用.

Solution 2: You can create a kind of filter-state class and store it in user profile. As a result users will not be bothered in specifying filter parameters again and again and these preferences would be available every time user logs in.

Session用于存储特定于用户的信息,该信息可从所有网页访问,并且下次用户登录时将不需要.

Session is used to store user-specific information that could be accessible from all web pages and will not be needed on next time user logs in.

Scenario 3:假设有一些电子商务应用程序,并且市场营销人员希望实时地查看网站上正在发生的事情,即查看某些用户在登录时访问了哪些页面.请考虑这种情况作为选定的用户活动快照.

Scenario 3: Assume there is some e-commerce application and marketing people want to see what is happening on site in close real time manner, i.e. see what pages were visited by certain users while they were logged in. Consider this scenario as a selected users activity snapshot.

Solution 3:在这里,您可以使用session记录用户访问过哪些URL,然后为营销人员生成报告.

Solution 3: Here you can use session to log what URLs were visited by users and then generate report for marketing people.

对于状态管理,您还可以参考另一篇MSDN文章

As for state management you can also reffer to another MSDN article ASP.NET State Management Overview.

另一个好答案,突出显示了管理asp.net应用程序状态的对象之间的区别.

Another good answer which highlights the difference between objects that are managing asp.net application state.

希望这对您有所帮助.

这篇关于ASP.NET中的会话,缓存和配置文件之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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