ASP.Net caching manager I have a Cache Helper Class.

using System;
using System.Web;

public static class CacheHelper
{
    /// &lt;summary&gt;
    /// Insert value into the cache using
    /// appropriate name/value pairs
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;Type of cached item&lt;/typeparam&gt;
    /// &lt;param name="o"&gt;Item to be cached&lt;/param&gt;
    /// &lt;param name="key"&gt;Name of item&lt;/param&gt;
    public static void Add&lt;T&gt;(T o, string key) 
    {
        // NOTE: Apply expiration parameters as you see fit.
        // I typically pull from configuration file.

        // In this example, I want an absolute
        // timeout so changes will always be reflected
        // at that time. Hence, the NoSlidingExpiration.
        HttpContext.Current.Cache.Insert(
            key,
            o,
            null,
            DateTime.Now.AddMinutes(1440),
            System.Web.Caching.Cache.NoSlidingExpiration);
    }

    /// &lt;summary&gt;
    /// Remove item from cache
    /// &lt;/summary&gt;
    /// &lt;param name="key"&gt;Name of cached item&lt;/param&gt;
    public static void Clear(string key)
    {
        HttpContext.Current.Cache.Remove(key);
    }

    /// &lt;summary&gt;
    /// Check for item in cache
    /// &lt;/summary&gt;
    /// &lt;param name="key"&gt;Name of cached item&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool Exists(string key)
    {
        return HttpContext.Current.Cache[key] != null;
    }

    /// &lt;summary&gt;
    /// Retrieve cached item
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;Type of cached item&lt;/typeparam&gt;
    /// &lt;param name="key"&gt;Name of cached item&lt;/param&gt;
    /// &lt;param name="value"&gt;Cached value. Default(T) if 
    /// item doesn't exist.&lt;/param&gt;
    /// &lt;returns&gt;Cached item as type&lt;/returns&gt;
    public static bool Get&lt;T&gt;(string key, out T value) 
    {
        try
        {
            if (!Exists(key))
            {
                value = default(T);
                return false;
            }

            value =  (T) HttpContext.Current.Cache[key];
        }
        catch
        {
            value = default(T);
            return false;
        }

        return true;
    }
}


and usage:

string key = "EmployeeList";
List&lt;Employee&gt; employees;

if (!CacheHelper.Get(key, out employees))
{
    employees = DataAccess.GetEmployeeList();
    CacheHelper.Add(employees, key);
    Message.Text =
        "Employees not found but retrieved and added to cache for next lookup.";
}
else
{
    Message.Text = "Employees pulled from cache.";
}


Do you see any improvement / issue?
/// &lt;summary&gt;
/// Insert value into the cache using
/// appropriate name/value pairs
/// &lt;/summary&gt;
/// &lt;typeparam name="T"&gt;Type of cached item&lt;/typeparam&gt;
/// &lt;param name="o"&gt;Item to be cached&lt;/param&gt;
/// &lt;param name="key"&gt;Name of item&lt;/param&gt;
public static void Add&lt;T&gt;(T o, string key)



I think this signature would be more useful like this:

/// &lt;summary&gt;
/// Insert value into the cache using
/// appropriate name/value pairs.
/// &lt;/summary&gt;
/// &lt;typeparam name="T"&gt;Type of cached item (inferred from usage).&lt;/typeparam&gt;
/// &lt;param name="key"&gt;A string used to uniquely identify the added value.&lt;/param&gt;
/// &lt;param name="value"&gt;Item/value to be cached.&lt;/param&gt;
public static void Add&lt;T&gt;(string key, T value)




This is misleading:


/// &lt;summary&gt;
/// Remove item from cache
/// &lt;/summary&gt;
/// &lt;param name="key"&gt;Name of cached item&lt;/param&gt;
public static void Clear(string key)
{
    HttpContext.Current.Cache.Remove(key);
}



Clear is usually a parameterless method that clears a container's contents. This method should be named Remove.




/// &lt;summary&gt;
/// Check for item in cache
/// &lt;/summary&gt;
/// &lt;param name="key"&gt;Name of cached item&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
public static bool Exists(string key)
{
    return HttpContext.Current.Cache[key] != null;
}



"Check for item in cache" doesn't really say what's going on. I realize it's trivially inferred from the method's name, but "Checks for existence of specified key in cache." would be totally unambiguous.




public static bool Get&lt;T&gt;(string key, out T value) 



I don't like the implementation of that method very much, there are too many exit points, some being redundant. Consider something like this:

public static bool TryGet&lt;T&gt;(string key, out T value) 
{
    bool result;

    try
    {
        if (Exists(key))
        {
            value =  (T)HttpContext.Current.Cache[key];
            result = true;
        }
    }
    catch(InvalidCastException)
    {
        value = default(T);
    }

    return result;
}