将数据导入会话 [英] Having data into session

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

问题描述

大家好,



我在DB中缺少记录。我需要按帐号搜索记录。每次我都不能去DB并获取记录。因为它会产生一些性能问题。所以我打算使用Session变量,它将存储缺少记录并使用LINQ查询,我计划获取帐户详细信息。



这是一个好主意吗?或者我需要改变我的方法吗?



任何人都可以帮我吗?

Hi All,

I have Lacks of records in DB. I need to search the record by account number. Each and every time i cant go to DB and fetch record. Since it will make some performance issue. So i m planning to use Session variable, which will store Lacks of record and using LINQ query , I m planning to get the account details.

Is it a good idea? Or do i need to change my approach?

Can any one help me on this ?

推荐答案

是的,您的方法很好,而不是每次都获取数据一次并将数据存储到一个状态变量中,并在需要时使用该变量检索它。在使用状态变量之前,您应该清楚所有状态管理概念以及我们需要使用的位置以及优缺点等等。然后,只有您了解在特定情况下使用哪个状态变量。



如果你想存储批量数据Session是个不错的选择,但是如果数据很小则使用viewstate而不是session。
Yes, your approach is good instead of hitting DB everytime get the data one time and store it into one state variable, and retrieve it whenever you required by using that variable. Before using the State variables you should be very clear of all statemanagement concepts and where we need to use and what are the advantages and disadvantages etc.. then only you come to know which state variable to use in particular scenario.

If you want to store bulk data Session is the good option, but if the data is small then use viewstate instead of session.


它取决于您存储了多少数据以及您拥有多少用户。如果您要存储大量数据,并且您拥有大量用户,则使用会话将使用大量资源。您的另一个问题是数据无效时会发生什么?或者什么时候从会话中删除数据?此外,如果多个用户的数据相同,您将拥有多个副本。



另一种方法是使用Cache代替,因为您可以设置绝对或滑动该数据到期,因此在未使用时将被删除,并且如果可能的话,它将允许多个用户共享相同的数据。
It depends how much data you are storing and how many users you have. If you're storing a lot of data, and\or you have a lot of users then using the Session will use a lot of resources. Your other issue is what happens when the data becomes invalid? Or when does the data get removed from the Session? Also if the data is the same for multiple users you will have multiple copies.

An alternative would be to look at using Cache instead as you can set absolute, or sliding expiry of that data so it is deleted when not used, and it will allow multiple users to share the same data if that is possible.


这篇关于将数据导入会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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