.NET BUG in Add method of Cache class?

  • Thread starter Thread starter Eric Gates
  • Start date Start date
E

Eric Gates

In MS documentation for "Add" method of "Cache" class, it says
"Calls to this method will fail if an item with the same key parameter is
already stored in the Cache."

However, when I did the following from an aspx webpage, I did not get any
exception. Is this a .NET BUG?

string key = "111";
Cache.Add(key, "222", null, DateTime.Now.AddSeconds(60), TimeSpan.Zero,
CacheItemPriority.Normal, null);
Cache.Add(key, "222", null, DateTime.Now.AddSeconds(60), TimeSpan.Zero,
CacheItemPriority.Normal, null);


Thanks,

Eric
 
Eric Gates said:
In MS documentation for "Add" method of "Cache" class, it says
"Calls to this method will fail if an item with the same key parameter is
already stored in the Cache."

However, when I did the following from an aspx webpage, I did not get any
exception. Is this a .NET BUG?

string key = "111";
Cache.Add(key, "222", null, DateTime.Now.AddSeconds(60), TimeSpan.Zero,
CacheItemPriority.Normal, null);
Cache.Add(key, "222", null, DateTime.Now.AddSeconds(60), TimeSpan.Zero,
CacheItemPriority.Normal, null);

The call will fail, but it won't throw an exception - instead, it'll
return the previous value. (See the return part of the docs.) Basically
it won't actually do the add, but it won't throw an exception. At
least, that's how I read the docs - but I agree they could be clearer.
 
I did another quick test. You are right. Here the "fail" means doing
nothing.

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top