Application state vs. Cache API

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
 
S

Scott Allen

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

Paul Glavich [MVP - ASP.NET]

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
 
S

Steven Cheng[MSFT]

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
 
D

Daniel Walzenbach

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
 
H

Harry Simpson

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
 

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

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top