line

Power of .net Generic

using System;
using System.Collections.Generic;
using System.Text;

///
/// Application Cache class
/// A static class to manage the cached values by keys in dochunter application.
///
public static class DHCache
{
private static Dictionary cache = new Dictionary();

///
/// Add a new cache item for web application
///
/// Type of the value
/// Cache key name
/// Cachable value
public static void Add(string key, T value)
{
if (!cache.ContainsKey(key))
{
cache.Add(key, value);
}
else
{
cache[key] = value;
}
}

///
/// Remove a cached value by key from web application cache
///
/// Cache key name
public static void Remove(string key)
{
cache.Remove(key);
}

///
/// Get the cached value by key from web application cache
///
/// Type of the cached value
/// Cache key name
/// Cached value
public static T Get(string key)
{
if (!cache.ContainsKey(key))
{
return default(T);
}
else
{
return (T)cache[key];
}
}

///
/// Checks if the cached item already exists in web application cache
///
/// Cache key name
/// True if the cached item already exists. False otherwise
public static bool Exists(string key)
{
return cache.ContainsKey(key);
}
}