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: 
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.
well the text files won't be large so it would be better to store them in a database