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. Cache vs Application variable

Cache vs Application variable

Scheduled Pinned Locked Moved ASP.NET
databasevisual-studioquestion
2 Posts 2 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.
  • H Offline
    H Offline
    honeyman_can
    wrote on last edited by
    #1

    Can someone please me out? I got a translatable website where all the translations are currently stored in a DB. I have loaded them into a Dictionaries ect so I need to do is just access them. What are the implications or advantages of storing it in the cache and application variable respectively? I can't seem to see when is it appropriate to use either? Thanks in advance

    T 1 Reply Last reply
    0
    • H honeyman_can

      Can someone please me out? I got a translatable website where all the translations are currently stored in a DB. I have loaded them into a Dictionaries ect so I need to do is just access them. What are the implications or advantages of storing it in the cache and application variable respectively? I can't seem to see when is it appropriate to use either? Thanks in advance

      T Offline
      T Offline
      Tim Kohler
      wrote on last edited by
      #2

      The Applicaton state (i.e. Application["myVariable"]) and Application Cache (System.Web.HttpContext.Current.Cache.Add(...) in the System.Web.Caching namespace) are similar in purpose. That being that they cache non user specific data in memory on a web server. The app cache however, offers the following advantages: 1. You can set an expiration policy (sliding, absolute) that dictates when your item will be removed from the memory space. This can be useful with sliding expiration to not hold large items in the cache after they haven't been accessed in say 10 minutes. The absolute is useful if you have mostly static data you want to cache but say it gets updated in its source periodically. You can set the absolute expiration to flush it out of your web app. Coupling that idea with #2: 2. You can set an expiration delegate that will get called when the item is removed from the cache. This can be useful to refresh a stale cache in the case of absolute expiration. Say you have a set of items you offer for sale. You might choose to cache some part of that set. If you realize that your set only changes say in the middle of the night, you might set the absolute expiration accordingly and string an expiration delegate onto it. Then when the item is removed from the cache, you can run some code via the delegate to build a new, updated set and cache that. So, all in all, app cache lets you be less of a memory hog by controlling when your item is removed. It also allows some interesting ways to keep the cache in sync in certain situations.

      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