Static Dictionary<string,object> vs Cache

  • Thread starter Thread starter Paul.N.Phillips
  • Start date Start date
P

Paul.N.Phillips

I am using a static dictionary to objects (like cache) but woundered
if it is better to use cache.

Which one would should I use?
 
It depends on what you need ;-p

Most importantly, most cache implementations will provide thread
safety, which a static dictionary (by itself) doesn't - you'd need to
do your own synchronization. But cache implementations may also offer
options for lifetime, dependencies (file system, etc), serialization,
etc.

Marc
 
Where you use this,

It makes a big difference by instance if it is in
A web application
A forms application
A service application

And that is then the start.

Cor
 
Where you use this,
[web/forms/service]

My understanding is that it *used* to make a lot more difference,
since without "web" it didn't fire up a thread to recover the memory -
but I thought that was now fixed, allowing you to use the cache from
System.Web in any scenario? Correct me if I am wrong...

And of course that is just the System.Web cache; most implementations
are architecture neutral / agnostic.

Marc
 
Where you use this,
[web/forms/service]

My understanding is that it *used* to make a lot more difference,
since without "web" it didn't fire up a thread to recover the memory -
but I thought that was now fixed, allowing you to use the cache from
System.Web in any scenario? Correct me if I am wrong...

And of course that is just the System.Web cache; most implementations
are architecture neutral / agnostic.

Marc

Hi thank you for that.

I am using a Web application. The reason why I am asking this
question is the memory usage, as currently we are getting out of
memory errors, though these dictionary objects only take 27 meg of
memory, would putting these into Cache would be better from a memory
point of view?
 
Well, the cache is likely to have more sophisticated scavenging
rules... but this isn't a great help if your code detects the missing
cache data and simply re-fetches it.

If you are getting memory errors, I'd first want to understand where
all the memory has gone, with profiling tools (the inbuilt performance
counters are the first thing to look at - what is the memory graph
like? a diagonal line is never good...)
 
Hi thank you for that.

I am using a Web application. The reason why I am asking this
question is the memory usage, as currently we are getting out of
memory errors, though these dictionary objects only take 27 meg of
memory, would putting these into Cache would be better from a memory
point of view?

27 MB of memory *per* dictionary, or 27MB of memory *for all* dicionaries?

If it's per dictionary, then it wouldn't take too much to overload a server with
even 4GB+ of RAM (assuming a single sesssion consumes only the 27MB in the
cache, it's roughly 148 sessions to eat 4GB).

That's a lot of memory to consume either way. What are you storing in it?

Chris.
 

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