[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

System.Web.Caching.Cache.Insert periodically fails to insert in fw

Donald Joppa

6/5/2007 9:24:00 PM

After converting a large code base from 1.1 to 2.0 in our unit tests we're
periodically (and unpredictably) encountering a situation where an item in
the cache is updated with Cache.Insert(), but a subsequent attempt to
retrieve the cached value returns null.

The insert statement looks like this:
mCache.Insert(key, value, new
CacheDependency((string[])mDepFiles.ToArray(typeof(string)), mDepKeys),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, priority, mOnRemove);

Here's the code that attempts to retrieve the entry from the cache:

Hashtable SettingsCollection = (Hashtable)mGC[GetGlobalCacheKey()];

if (null == SettingsCollection)
{
Hashtable ht1 = RefreshCachedSettings(currKey);
Hashtable ht2 = (Hashtable)mGC[GetGlobalCacheKey()];

if (ht2 == null)
{
// log it but don't throw it
}
return ht1;
}

What's happening is in this code when it tries to put the settings into
SettingsCollection it gets a null back, so it drops into the if statement and
attempts to refresh the cache settings. That code makes a call to
cache.insert, but when it comes back and attempts to put the cache value into
HT2, it gets a null respose.

I've seen a few posts that describe similar behavior, but none of them
identified the root cause of the behavior.