Monday, November 22, 2010

Object Caching in ASP.NET

System.Web.Caching.Cache is used to cache objects on serverside.
e.g.
public IQueryable<User> GetUsersList()
{
UserModel objUsers = new UserModel();
if (HttpContext.Current.Cache["USERS"] == null)
HttpContext.Current.Cache.Add("USERS", objUsers.GeFakeUserList(), null, Cache.NoAbsoluteExpiration, System.TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable, null);
return (IQueryable<User>)HttpContext.Current.Cache["USERS"];
}
 

No comments:

Post a Comment