Problem with caching

  • Thread starter Thread starter hth
  • Start date Start date
H

hth

Hi

I usually check the key and value in my cache with following code:

foreach (DictionaryEntry objItem in Cache)
{
lblCache.Text += "<li>" + objItem.Key;
lblCache.Text += "=" + objItem.Value.ToString();
}

but if I change my web.config file and save it, the code above that had
give me expecting result, give me noting.
Does someone know why this is happening and if there is a way around
it?

Helgi
 
hth said:
Hi

I usually check the key and value in my cache with following code:

foreach (DictionaryEntry objItem in Cache)
{
lblCache.Text += "<li>" + objItem.Key;
lblCache.Text += "=" + objItem.Value.ToString();
}

but if I change my web.config file and save it, the code above that
had give me expecting result, give me noting.
Does someone know why this is happening and if there is a way around
it?

Helgi

When you change web.config, the application is restarted.
That's why the Cache (and Application and Session) is empty.
There is no way around it, except to use a database (or file)
to store those items, but that's not how tou want to use a cache.

Especially with Cache it's best to accept that values may be missing:
try if it's there. If so, fine. If not, (re)create that value (or object)
and store it for the next time.

Hans Kesting
 
Hi,
The reason i think is
When you are saving the web.config after making changes it causes the
application to restart.. And cache data is not persisted across application
restarts.. and hence you are losing information in the cache..
I think this is a very useful tip if you have to make changes to the
web.config and still not loose cache data
http://www.devx.com/vb2themax/Tip/18880
 

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