Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Application variables VS Cache objects !!

Application variables VS Cache objects !!

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-netsql-server
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mittalpa
    wrote on last edited by
    #1

    Hi I am using VB.net/ASP.NET and SQL Server 2000 for asp.net application. I am using Country table data several places in my application. For that I am using Application("Country") variable to store its data, so that I can use it anytime. Should I use Cache("Country") instead? With this approache, the problem is if Cache object expires, then I need to make another database server trip, which can be costly affair. Anyway, both stay in server's memory. Please advice which one is better. Thanks in advance. Pankaj

    S 1 Reply Last reply
    0
    • M mittalpa

      Hi I am using VB.net/ASP.NET and SQL Server 2000 for asp.net application. I am using Country table data several places in my application. For that I am using Application("Country") variable to store its data, so that I can use it anytime. Should I use Cache("Country") instead? With this approache, the problem is if Cache object expires, then I need to make another database server trip, which can be costly affair. Anyway, both stay in server's memory. Please advice which one is better. Thanks in advance. Pankaj

      S Offline
      S Offline
      Sean Winstead
      wrote on last edited by
      #2

      If you put something in the cache, you can specify that it never expires. Even if it did expire, how much does it really cost to read it from the database again? Is it that noticeable if it is read once every hour? Every 2 hours? Every 4 hours? Sean Winstead

      M 1 Reply Last reply
      0
      • S Sean Winstead

        If you put something in the cache, you can specify that it never expires. Even if it did expire, how much does it really cost to read it from the database again? Is it that noticeable if it is read once every hour? Every 2 hours? Every 4 hours? Sean Winstead

        M Offline
        M Offline
        mittalpa
        wrote on last edited by
        #3

        Thanks for reponse Sean. Though I can read from database again. But, why do I need to? If I have a way to store the information as a long as application runs, then shouldn't I use it? Thanks Pankaj Follow your goals, Means will follow you ---Gandhi---

        S 1 Reply Last reply
        0
        • M mittalpa

          Thanks for reponse Sean. Though I can read from database again. But, why do I need to? If I have a way to store the information as a long as application runs, then shouldn't I use it? Thanks Pankaj Follow your goals, Means will follow you ---Gandhi---

          S Offline
          S Offline
          Sean Winstead
          wrote on last edited by
          #4

          Though I can read from database again. But, why do I need to? If I have a way to store the information as a long as application runs, then shouldn't I use it? Yes. The point I was trying to make is that it may not be worth worrying about if there is nt that much data to read and it is not read too often. But as I mentioned, you can tell the cache that the data never expires and the point is moot. Sean Winstead

          B 1 Reply Last reply
          0
          • S Sean Winstead

            Though I can read from database again. But, why do I need to? If I have a way to store the information as a long as application runs, then shouldn't I use it? Yes. The point I was trying to make is that it may not be worth worrying about if there is nt that much data to read and it is not read too often. But as I mentioned, you can tell the cache that the data never expires and the point is moot. Sean Winstead

            B Offline
            B Offline
            Blake Coverett
            wrote on last edited by
            #5

            The whole point of the cache is that even items that have not expired may be scavenged when there is memory pressure. Better to slow down because you have to reread the database and recreate the cached data than to fault completely because an allocation can not be performed. And that's the answer for the original poster as well. Stick your country list in the cache with no expiration but always access it via a method that tries the cache and if it isn't there recreates it from the database and caches it. This gives you multiple advantages: only one piece of code knows how to to create the list from the database; you don't populate the cache till you need to the first time; your application degrades gracelly if memory get's tight; unless you have memory pressure your performance is exactly the same as putting it in application state, i.e. one read from the database all other reads from memory. -- -Blake (com/bcdev/blake)

            S M 2 Replies Last reply
            0
            • B Blake Coverett

              The whole point of the cache is that even items that have not expired may be scavenged when there is memory pressure. Better to slow down because you have to reread the database and recreate the cached data than to fault completely because an allocation can not be performed. And that's the answer for the original poster as well. Stick your country list in the cache with no expiration but always access it via a method that tries the cache and if it isn't there recreates it from the database and caches it. This gives you multiple advantages: only one piece of code knows how to to create the list from the database; you don't populate the cache till you need to the first time; your application degrades gracelly if memory get's tight; unless you have memory pressure your performance is exactly the same as putting it in application state, i.e. one read from the database all other reads from memory. -- -Blake (com/bcdev/blake)

              S Offline
              S Offline
              Sean Winstead
              wrote on last edited by
              #6

              Good point. Sean Winstead

              M 1 Reply Last reply
              0
              • S Sean Winstead

                Good point. Sean Winstead

                M Offline
                M Offline
                mittalpa
                wrote on last edited by
                #7

                thanks guys. Follow your goals, Means will follow you ---Gandhi---

                1 Reply Last reply
                0
                • B Blake Coverett

                  The whole point of the cache is that even items that have not expired may be scavenged when there is memory pressure. Better to slow down because you have to reread the database and recreate the cached data than to fault completely because an allocation can not be performed. And that's the answer for the original poster as well. Stick your country list in the cache with no expiration but always access it via a method that tries the cache and if it isn't there recreates it from the database and caches it. This gives you multiple advantages: only one piece of code knows how to to create the list from the database; you don't populate the cache till you need to the first time; your application degrades gracelly if memory get's tight; unless you have memory pressure your performance is exactly the same as putting it in application state, i.e. one read from the database all other reads from memory. -- -Blake (com/bcdev/blake)

                  M Offline
                  M Offline
                  mittalpa
                  wrote on last edited by
                  #8

                  thanks.. Since I found out a gem called HttpContext.Current , I am all up for Cache now. :) Pankaj Follow your goals, Means will follow you ---Gandhi---

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups