Question: 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?

Answer: 
Since you are using the .NET Framework, you should probably use one of the many .NET caching features. 

You may want to check the following articles for some tips on the topic:

* [ASP.NET Caching Features](http://authors.aspalliance.com/aspxtreme/webapps/aspcachingfeatures.aspx)
* [MSDN: ASP.NET Caching: Techniques and Best Practices](http://msdn.microsoft.com/en-us/library/aa478965.aspx)
You should rather cache it in memory if you want a reasonable chance for it to be an improvment over the database.

The database is disk based with a memory cache, so if you cache it on disk that will only be faster if your files happens to be in the disk cache in memory. As the database cache is a lot larger than the disk cache, it's probable that a disk based cache would actually make it slower.