问题
I will be populating DataTable
and other controls
from a complex object
.
- Where should I store such an
object
? - At what size does session variables starts affecting the performance of page?
回答1:
Data in the Session
object is stored in memory on the server. Thus the storage limit is the memory available to the server. This data is not sent to the client at any stage, unless you explicitly do so. Instead the MVC code sends a cookie to the client browser once you have assigned any value to the Session object. The value of this cookie is then used to uniquely identify the session.
So...
- The
Session
object is designed specifically so that you can store session-specific data on the server, so is a suitable place for you to put session-specific data structures like you describe. - Because the
Session
object is server-side only, usingSession
to store the results of computationally expensive operation that is invariant across multiple page refreshes will speed up page loads, since you can use the previous result instead of having to create it again. Unless you blow out the memory limits on the server, you're not going to see any performance degradation.
回答2:
- If it's a per-session object, the Session dictionary is a reasonable place to store it
- If you are using the InProcess session store, the size of the object never affects page performance (at least until all of the data causes the process to swap). Other session stores may have a slight impact, based on how long it takes to move the data from e.g. SQL to the local process. This will be fast until your object gets really big.
来源:https://stackoverflow.com/questions/14970659/are-there-limits-for-session-variables-in-asp-net