I always wondered how exactly you’d handle caching of database-values (in C#, ASP.NET) so you e.g. don’t reload several DataSource-Bound ASP-Controls or don’t have to reload them everytime you use a certain backend method.
Let’s just take the following example:
aspx.cs-File:
List<FormElement> elements = FormElement.GetForForm(Session["FormName"].ToString());
Backend-Method:
public static List<FormElement> GetForForm(string fName)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("select Rank, Control, Variable from inspire.dbo.formelement where formid=(select id from inspire.dbo.form where name=@name)", Database.Conn);
cmd.Parameters.Add(new SqlParameter("@name", fName));
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
return dt.Rows.ToList<FormElement>(item => new FormElement(item));}
How exactly would I handle caching here?
Thanks,
Dennis
what we have done for the caching:
in page side, use a global container (eg. dataset) to store all the required data, each data add a time flag for it
in backend side, use a same container to store the data, and also with the time flag
when page refresh, compare the time flag with current datetime, get data from that container;
or send a refresh_fetch to backend side, backend will get data from db and update caching content for its container, then send back the updated data to page
page update its container and display out
the flow is simply like this, however, based on real situation, the container, the refresh strategy… maybe different