Application state vs. Cache API

  • Thread starter Thread starter Daniel Walzenbach
  • Start date Start date
D

Daniel Walzenbach

Hi,



I need to cache infrequently changed data used by the entire application.
Does anybody know whether using Application state
(Application["YourGlobalState"] = somevalue;) or the Cache API
(Cache.Insert) is more preferable?



Thanks a lot



Daniel
 
The cache object is more flexible in the long run. You can set a
duration and a priority for the cached item, for instance.
 
The cache is good, but it is considered volatile. There is never any
guarantee that the data is there. The item may be removed when it expires or
some condition is met (something you explicitly set), or the runtime may
remove the item when memory gets low. In contrast, the application variables
are there for the duration of the applications life, unless explicitly
removed by you and it provides methods to synchronise access to the
varibales as well. (.Lock for example).

--
- Paul Glavich
Microsoft MVP - ASP.NET


Scott Allen said:
The cache object is more flexible in the long run. You can set a
duration and a priority for the cached item, for instance.

--
Scott
http://www.OdeToCode.com

Hi,



I need to cache infrequently changed data used by the entire application.
Does anybody know whether using Application state
(Application["YourGlobalState"] = somevalue;) or the Cache API
(Cache.Insert) is more preferable?



Thanks a lot



Daniel
 
Hi Daniel,

I think Scott's suggestion is reasonable since the ASP.NET's Cache Object
not only provide the share space across the whole application scope but
also provide many mechenism to control's lifecyle(the different kind of
dependences). Here are some tech articles on ASP.NET caching:

#ASP.NET Caching: Techniques and Best Practices
http://msdn.microsoft.com/library/en-us/dnaspp/html/aspnet-cachingtechniques
bestpract.asp?frame=true

#Using the ASP.NET Application Cache to Make Your Applications Scream
http://www.codeguru.com/columns/Experts/article.php/c4231/

#Manage Detail Pages Across Multiple Platforms with Centralized Data Caching
http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/ht
ml/cencachv3.asp

Hope also helpful.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Thank you!

Daniel

Steven Cheng said:
Hi Daniel,

I think Scott's suggestion is reasonable since the ASP.NET's Cache Object
not only provide the share space across the whole application scope but
also provide many mechenism to control's lifecyle(the different kind of
dependences). Here are some tech articles on ASP.NET caching:

#ASP.NET Caching: Techniques and Best Practices
http://msdn.microsoft.com/library/en-us/dnaspp/html/aspnet-cachingtechniques
bestpract.asp?frame=true

#Using the ASP.NET Application Cache to Make Your Applications Scream
http://www.codeguru.com/columns/Experts/article.php/c4231/

#Manage Detail Pages Across Multiple Platforms with Centralized Data Cachinghttp://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/ht
ml/cencachv3.asp

Hope also helpful.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
True but as with all caching, one ALWAYS checks to see if the data is in the
cache and if not gets fresh data. So unless connection is iffy, this really
should be a concern.

Harry

Paul Glavich said:
The cache is good, but it is considered volatile. There is never any
guarantee that the data is there. The item may be removed when it expires
or
some condition is met (something you explicitly set), or the runtime may
remove the item when memory gets low. In contrast, the application
variables
are there for the duration of the applications life, unless explicitly
removed by you and it provides methods to synchronise access to the
varibales as well. (.Lock for example).

--
- Paul Glavich
Microsoft MVP - ASP.NET


Scott Allen said:
The cache object is more flexible in the long run. You can set a
duration and a priority for the cached item, for instance.

--
Scott
http://www.OdeToCode.com

Hi,



I need to cache infrequently changed data used by the entire
application.
Does anybody know whether using Application state
(Application["YourGlobalState"] = somevalue;) or the Cache API
(Cache.Insert) is more preferable?



Thanks a lot



Daniel
 
Back
Top