Shawn
Shawn

Reputation: 19803

What is the difference between Application and Cache in ASP.NET?

What the difference between Application("some-object") and Cache("some-object") in ASP.NET?

Upvotes: 5

Views: 9703

Answers (4)

Thomas Bratt
Thomas Bratt

Reputation: 51822

  • Application is very similar to a static dictionary that lasts for the lifetime of the web application.
  • Cache provides more features that you would expect in a cache, such as expiry and callbacks on expiry.
  • With the most common usage scenario, items can automatically 'disappear' from the cache. This does not happen with Application.
  • Cache appears to be the best practice option.

Upvotes: 1

sajid khan
sajid khan

Reputation:

Application and cache are both application level storage of item, but difference is that in usage cenario , like cache is more flexible can do much more like scavenges ( removes unimortent item from cache automaticaly) ,but cache on othere side is volatilemeans that it is not sure that data will stay for application life .But Application is more relaibrel ,data stays when ever application is running but it is simple .

Upvotes: 1

bang
bang

Reputation: 5221

According to MS, Application storage is only preserved for backward compatibility with classic ASP applications so use the Cache because it's smarter and thread-safe.

Upvotes: 4

Quintin Robinson
Quintin Robinson

Reputation: 82345

Application is an application wide, no timeout (except when the pool restarts) dictionary. The cache is a temporary repository for common cache storage.

This And This might help clarify the differences and usages.

Here is another one.

Upvotes: 9

Related Questions