Hi,
I've stumbled onto a problem when using the caching object in ASP.Net.
I'm placing a static dataset to the cache as the data only changes
once a day. Whilst writing to the cache I'm using a lock using code
like below (just typed this in);
Cache thisCache = HttpContext.Current.Cache
lock(thisCache)
{
thisCache.Insert(....)
}
When reading from the cache I'm using
Dataset a = HttpContext.Current.Cache[cacheKey]
if (a==null)
{
// Info doesnt exist...Go and create the data and write it to the
cache!
}
else
{
//I've got the info...
}
All appears to work great...until the system is placed under load -
then strange things occur. For example a empty dataset is returned
(not a null dataset but a dataset which contains the dataset schema
but has no data)
Do anyone have any ideas? I've been informed by MS that the Cache
object is meant to be thread safe, so in theory the lock isn't even
required.
Cheers,
Mat