use Session or Cache?

Results 1 to 4 of 4

Thread: use Session or Cache?

  1. #1
    Join Date
    Dec 1969

    Default use Session or Cache?

    or i suppose it doesn&#039;t matter since its all stored in memory anyways...<BR><BR>on my one project that is pretty high traffic, i have people login, i store a generated code in a cookie on their computer, and then i assign their settings in Session (this is the current live ASP 3.0 site version)<BR><BR>i am rewriting the whole site in ASP.NET and am thinking of storing a HashTable for 15 mins of each user&#039;s settings<BR><BR>pros/cons of doing that over using just session? the Cache object seems very powerful... just want to confirm it before i walk that path with this site, this whole rewrite is geared to nothing but resource optimization

  2. #2

    Default RE: use Session or Cache?

    Oranges vs Carrots?<BR><BR>Separate the problem from the implementation.<BR><BR>Create an object to hold the settings, maybe even with a ".Current" property.<BR><BR>You want to abstract it in such a way as to be able to optimize later rather than prematurely optimizing now.<BR><BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default unfortunately

    your reply makes zero sense and doesn&#039;t help much

  4. #4

    Default RE: unfortunately

    The session and cache are for very different roles, the cache is not really a place for user specific data.<BR>It is more like the Application object.<BR><BR>Some sample code with GetCurrentUserPref()<BR>It uses the HttpContext.Current.Items collection so that the object only gets created once per request.<BR><BR>[code language="c#"]<BR>using System;<BR>using System.Web;<BR>using System.Web.UI;<BR><BR>namespace TemplatedSampleSite.aspmessageboard<BR>{<BR> public class UserPref<BR> {<BR> private bool _isAdmin;<BR> private bool _isManager;<BR> static string contextKey = typeof(UserPref).Name;<BR> static string methodKey = contextKey+"." + "GetCurrentUserPref";<BR> private UserPref(bool isAdmin,bool isManager)<BR> {<BR> _isAdmin =isAdmin;<BR> _isManager = isManager;<BR> }<BR> public bool IsAdmin<BR> {<BR> get<BR> {<BR> return _isAdmin;<BR> }<BR> }<BR> public bool IsManager<BR> {<BR> get<BR> {<BR> return _isManager;<BR> }<BR> }<BR> static public UserPref GetCurrentUserPref(string id)<BR> {<BR> UserPref userPref = HttpContext.Current.Items[methodKey + id] as UserPref;<BR> if(userPref == null)<BR> {<BR> //This is where the real load preferences logic goes<BR> if(id=="boss")<BR> {<BR> userPref = new UserPref(true,true);<BR> }<BR> else<BR> {<BR> userPref = new UserPref(false,false);<BR> }<BR> HttpContext.Current.Items[methodKey + id] = userPref;<BR> }<BR> return userPref; <BR> }<BR> }<BR>}<BR><BR>[/code]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts