I've got this piece of caching code
public static ICollection<Messages> GetMessages()
{
if (System.Web.HttpContext.Current.Cache["GetMessages_" + user_id] == null)
{
using (DataContext db = new DataContext())
{
var msgs = (from m in db.Messages
where m.user_id == user_id
&& m.date_deleted == null
select m).ToList();
System.Web.HttpContext.Current.Cache.Insert(
"GetMessages_" + user_id, msgs, null,
DateTime.Now.AddMinutes(5), TimeSpan.Zero);
}
}
return System.Web.HttpContext.Current.Cache["GetMessages_" + user_id]
as ICollection<Messages>;
}
The first time it runs, it pulls the data from a SQL table, and takes about 1500 ms. Every subsequent call takes about 600ms. The collection i'm testing on currently contains just 3 objects, each with minimal data (a string, 3 datetime fields, 3 bools and 5 ints)
Is this normal? loading a page with this tiny amount of data on it takes almost 2 seconds, every single time.
[FYI this is just running on a dev machine, not a fully fledged web server. data is being pulled from a remote server but that should only affect the initial page load]