Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 711499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:44:32+00:00 2026-05-14T04:44:32+00:00

I am checking out the OutputCacheProvider in ASP.NET 4.0 and using it to store

  • 0

I am checking out the OutputCacheProvider in ASP.NET 4.0 and using it to store my output cache into the MongoDb database. I am not able to understand the purpose of Add method which is one of the override methods for OutputCacheProvider. The Add method is invoked when you have VaryByParam set to something. So, if I have VaryByParam = “id” then the Add method will be invoked.

But after the Add the Set is also invoked and I can insert 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 the PathAndQuery to get the params of the QueryString and then do a MD5 on the key and save it into the MongoDb database.

It seems like the Add method will be useful if I am doing something like VaryByParam = “custom” or something.

Can anyone shed some light on the Add method of OutputCacheProvider?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:44:32+00:00Added an answer on May 14, 2026 at 4:44 am

    They are similar, but there is a slight difference. Looking at the MSDN documentation for the OutputCacheProvider class

    • Set – “Inserts the specified
      entry into the output cache,
      overwriting the entry if it is
      already cached”
    • Add – “Inserts
      the specified entry into the output
      cache.”

    The remarks for “Add” go on to say

    “If there is already a value in the
    cache for the specified key, the
    provider must return that value. The
    provider must not store the data
    passed by using the Add method
    parameters. The Add method stores the
    data if it is not already in the
    cache. If the data is in the cache,
    the Add method returns it”

    So for new values that aren’t already in the cache they will behave identically, but where the value already exists, Set updates it, whereas Add leaves the original value intact.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After checking out code for the first time from a repository into Eclipse using
I'm checking out Linq for NHibernate 2.1 to use in an ASP.NET MVC application
I was checking out this link: http://blogs.msdn.com/b/stuartleeks/archive/2011/01/25/asp-net-mvc-3-integrating-with-the-jquery-ui-date-picker-and-adding-a-jquery-validate-date-range-validator.aspx which describes creating a jquery datepicker for
Checking out the sample code from http://lukesampson.com/post/471548689/entering-and-exiting-https-with-asp-net-mvc written for ASP.NET MVC2, I noticed they
I'm checking out ASP.NET MVC RC2. Is the API documentation completely missing? I should
After checking out the official documentation , I am still not sure on how
Using paypal_base.dll and Payflow_dotNET.dll Have the following setup: SetExpressCheckoutRequestType.SetExpressCheckoutRequestDetails.AllowNote = 1 When checking out
I'm using SVNANT for checking out my project directory on my Windows XP machine.
I've just started checking out WebMatrix, and am running into a problem. I performed
I'm checking out the Delphi 2009 Trial, but run into problems with the generics

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.