Scale ASP.NET Apps Through Distributed Caching: Listing 1.
Distributed cache in a .NET application for application data.
// Check the Cache before going to the database.
void Load(Customer cust)
// Create a key to lookup in the cache.
// The key will be like "Customer:PK:1000"
string key = "Customer:CustomerId:" + cust.CustomerId.ToString();
Customer customer = (Customer)Cache[key];
if (customer == null)
// Item not found in the cache. Therefore, load from database.
// Now, let's add this object to the cache for future reference.
Cache.Insert(key, customer, null,
CacheItemPriority.Default, null );
Iqbal Khan is president, CEO and technology evangelist for Alachisoft in San Ramon, Calif., and a frequent contributor to TechNet Magazine.