Wednesday, October 21, 2009

ASP.Net Caching vs Caching Application block (CAB)

Why do we need caching?

  • Faster performance
  • Throughput and faster response time
  • To avoid expensive roundtrips
  • Data must always be available, even when the source, such as server is not available.

What influences caching?

The amount of data you cache and amount of time you cache.

What kind of data should be cached?

Frequently used general purpose data used in the lifetime of application should be cached

What kind of data should NOT be cached?

Data which is not frequently used or which is based on request or session

Which caching mechanism to use?

Caching application block or ASP.Net Caching mechanism

Caching application block:

We see value of caching application block when using durable storage like database or isolated storage for caching.The Caching Application Block integrates seamlessly with the Data Access Application Block for backing store functionality

Drawbacks:

  • Overhead of configuration files to manage cache policies.
  • Overhead of creating and managing backing stores
  • By default, cache manager writes to in-memory cache

However, the nonvolatile, persisted storage of data comes with a cost. While it is good to have data that will not disappear when a computer is shut off, the actual task of storing data can hinder performance. The most expensive performance costs typically involve the reading and writing of data to disk,

ASP.NET Cache

The .NET Framework includes the ASP.NET cache in the System.Web namespace. ASP.NET application developers access this cache through the System.Web.HTTPContext.Cache object. The ASP.NET cache was developed and tuned for ASP.NET applications. However, this cache can also be used outside of an ASP.NET application by accessing the System.Web.HTTPRuntime.Cache object. The ASP.NET cache requires the System.Web assembly.

We can cache user controls, page output caching, selective caching caching portion of page and post cache substitution.

Problems with caching:

  • Static data/memory overrun/
  • Performance hits/Database Invalidation
  • File invalidation & Data refresh problems

Caching scheme only works with in current appdomain but not suitable for webfarm/webgarden