Cache variable suddenly = null

B

bayam

I have a web application that inserts several enumerated lists into the Cache
on the Initialize event of global.asax:

Cache _cache = Context.Cache;
_cache.Insert("Countries", htCountries);

Sometime last night, the cached variable htCountries started to return a
null value, causing our code to crash. Nothing in the code assigns this
variable to null. Restarting the applicaton fixed the problem. (This
particular code has been around for 3 months, and this error has never
occurred before.)

Is there a know security exploit of the .NET Cache object that would allow a
hacker to do this?
 
P

Paul Glavich [MVP ASP.NET]

Any items stored in the cache are "volatile" and can be removed by the
system. Using the insert method you describe below, inserts the cached item
with a default priority. The default being "Normal". The MSDN docs explain
this as.

"Cache items with this priority level are likely to be deleted from the
cache as the server frees system memory only after those items with Low or
BelowNormal priority. This is the default."

As a best practice, never assume a cached item exists. Always check for NULL
first and re-insert into the cache if it is NULL if thats your want.
 
J

Joe Kaplan \(MVP - ADSI\)

Also, if you want to be notified when something gets removed from the cache,
attach the appropriate delegate so that you get called back when it happens.
You can then find out when and why the item got ejected and reinsert it back
into the cache if you need to.

Joe K.
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top