
Caching in Code
317
Session Object
In traditional ASP.NET, the Session object is similar to the Application object, in that objects
may be stored in memory on the current server along with a string cache key. The difference is that
the
Session object is not shared between users and expires entirely after a user has stopped inter-
acting with the Web site for some period of time (typically approximately 20 minutes). This makes
the
Session object ideal for storing user-specific information that is needed only for the current
browsing session, such as shopping cart data or user profile data. ASP.NET provides the ability to
store session data in a database or in memory, as well as on a single session server within your farm
that centralizes session data for all servers, but keeps it in memory.
When congured within SharePoint, however, session state data is always stored in a database. This
database is congured in the
web.config le of your web application, just like any ASP.NET appli-
cation, but you can use a PowerShell command to enable it. The session state database may be placed
on an entirely separate database server if your farm makes heavy use of the session. By default, ses-
sions are disabled on SharePoint farms. Only enable session state if it will be used by components on
your farm because the overhead of creating sessions for each user impacts scalability.
One advantage ...