We are writing a portal and like every portal we store html data in Db fro Modules. So I thought that I can cache each module in files. I use OnLoad event to check if there is a cache file for this Module, use that and else create cache file:
if (!IsPostBack)
{
string Path = AppDomain.CurrentDomain.BaseDirectory + "\\Cache\\Modules\\" + ModuleId + ".dat";
if (File.Exists(Path))
{
Controls.Clear();
Literal ltCache = new Literal();
ltCache.Text = File.ReadAllText(Path);
Controls.Add(ltCache);
}
else
{
base.OnLoad(e);
StringBuilder SB = new StringBuilder();
StringWriter SW = new StringWriter(SB);
HtmlTextWriter htmlTW = new HtmlTextWriter(SW);
//this.Visible = true;
this.RenderControl(htmlTW);
File.WriteAllText(Path, SB.ToString());
//this.Visible = false;
}
}
but know I doubt that it's a good idea. what do you think? retrieving data from file can slow server more than retrieving data from DB?