.NET 4.0 Implementing OutputCacheProvider

I check the OutputCacheProvider in ASP.NET 4.0 and use it to store my output cache in the MongoDb database. I cannot understand the purpose of the Add method, which is one of the override methods for OutputCacheProvider. The Add method is called when VaryByParam is set to something. So, if I have VaryByParam = "id", then the Add method will be called.

But after adding, Add Set is also called, and I can insert it into the MongoDb database inside the Set method.

public override void Set(string key, object entry, DateTime utcExpiry)
{
    // if there is something in the query use the path and query to generate the key 
    var url = HttpContext.Current.Request.Url;

    if (!String.IsNullOrEmpty(url.Query))
    {
        key = url.PathAndQuery;
    }

    Debug.WriteLine("Set(" + key + "," + entry + "," + utcExpiry + ")");  
    _service.Set(
        new CacheItem() { Key = MD5(key), Item = entry, Expires = utcExpiry }
    ); 
}

Inside the Set method, I use PathAndQuery to get the QueryString parameters, and then do MD5 on the key and save it in the MongoDb database.

It seems that the Add method will be useful if I do something like VaryByParam = "custom" or something like that.

- Add OutputCacheProvider?

+5
1

, . MSDN OutputCacheProvider class

""

" , . Add . Add , . , Add "

, , , , , Set , Add .

+8

All Articles