Static Dictionary<string,object> vs Cache

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul.N.Phillips@gmail.com

    Static Dictionary<string,object> vs Cache

    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?
  • Marc Gravell

    #2
    Re: Static Dictionary&lt;s tring,object&gt ; vs Cache

    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

    Comment

    • Cor Ligthert[MVP]

      #3
      Re: Static Dictionary&lt;s tring,object&gt ; vs Cache

      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

      <Paul.N.Phillip s@gmail.comschr eef in bericht
      news:c7546726-dddc-416b-a9e7-796cee185bc0@1g 2000prg.googleg roups.com...
      >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?

      Comment

      • Marc Gravell

        #4
        Re: Static Dictionary&lt;s tring,object&gt ; vs Cache

        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

        Comment

        • Paul.N.Phillips@gmail.com

          #5
          Re: Static Dictionary&lt;s tring,object&gt ; vs Cache

          On May 18, 5:41 pm, Marc Gravell <marc.grav...@g mail.comwrote:
          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?

          Comment

          • Marc Gravell

            #6
            Re: Static Dictionary&lt;s tring,object&gt ; vs Cache

            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...)

            Comment

            • Chris Shepherd

              #7
              Re: Static Dictionary&lt;s tring,object&gt ; vs Cache

              Paul.N.Phillips @gmail.com wrote:
              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.

              Comment

              Working...