Cache not working as expected

S

Steve Franks

I'm having a difficult time trying to do some basic caching of a string
using VS.NET 2005 Beta 2.

Here's the simple snippet I'm using in a method within my ASP.NET code
behind page.

if (Cache["foo"] == null)
{
Cache.Insert("fooa", m_mystring);
}

When I step through this code, the first time this code is hit the
cache[foo] is null so it goes to the Cache.Insert. This executes fine (no
exceptions) and all is well so far.

But then the next time this page runs, cache[foo] is still null. Why is
this? At one point I saw it work so that cache[foo] returned an object when
the method was called mutiple times within the same page request. But then
when I hit refresh in the browser, the next time this method ran it was
equal to null again. It seems to go back and forth between sometimes always
being null, and sometimes finding a match but only on mutilple passes from
the same browser request. Always when you hit refresh in the browser it
comes back as null - even when I've watchd it go through the Cache.Insert
via the debugger on the previous request!

Any idea what may be going on?

Thanks,

Steve
 
J

Jeremy S.

Hi Steve,
I hope the explanation is really this simple:
In thecode that you posted - you test for "foo" but you are inserting
"fooa". Your observation is expected given that difference. Make them both
"foo" or "fooa" and life should be good.

If you didin't post your real code (and what you actually posted is a model
and you just have a typo in your model), then maybe you should post your
actual code so we can know what's actually going on.

-HTH
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top