Reputation: 35194
I have made a generic handler (.ashx) to fetch some database values using jquery ajax. I have a few questions:
Why is the first call to the handler always the slowest one?
Is there any way to decrease the response-time from the point that the HTTP-get/post is made until i get back a response from the handler? My current code looks something like this:
public void ProcessRequest(HttpContext context)
{
HttpContext.Current.Response.ContentType = "application/json";
SOFAEntities ctx = new SOFAEntities();
JavaScriptSerializer serializer = new JavaScriptSerializer();
string systemKey = HttpContext.Current.Request["SystemKey"];
try
{
SYSTEM_AUDIT_SHEET auditSheet = ctx.SYSTEM_AUDIT_SHEET.Where(s => s.SYSTEM_KEY == systemKeyDec).Select(s => s).OrderByDescending(s => s.AUDIT_SHEET_VERSION).First();
HttpContext.Current.Response.Write(serializer.Serialize(auditSheet));
}
catch (Exception e)
{
HttpContext.Current.Response.Write(serializer.Serialize(new ErrorObj() { ErrorMessage = e.Message }));
}
}
Upvotes: 1
Views: 441
Reputation: 700342
1: There are several possible reasons, which all can add up to make the first request slower, like:
2: You could serialise the objects manually, instead of using the generic serialiser, which uses reflection.
Upvotes: 1