ASP.NET caching helper I'm willing to simplify the use of the ASP.NET cache.

I wrote this helper class:

public static class CacheHelper
{
    public static T GetCached&lt;T&gt;(string key, Func&lt;T&gt; initializer, DateTime absoluteExpiration)
    {
        return GetCached(key, initializer, Cache.NoSlidingExpiration, absoluteExpiration);
    }
    public static T GetCached&lt;T&gt;(string key, Func&lt;T&gt; initializer, TimeSpan slidingExpiration)
    {
        return GetCached(key, initializer, slidingExpiration, Cache.NoAbsoluteExpiration);
    }
    public static T GetCached&lt;T&gt;(string key, Func&lt;T&gt; initializer, TimeSpan slidingExpiration, DateTime absoluteExpiration)
    {
        var httpContext = HttpContext.Current;

        if (httpContext != null)
        {
            var obj = httpContext.Cache[key];
            if (obj == null)
            {
                obj = initializer();
                httpContext.Cache.Add(key, obj, null, absoluteExpiration, slidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
            }
            return (T)obj;
        }
        else
        {

            return initializer(); // no available cache
        }
    }
}


The idea is to let the developer write its method as usual, but wrapping it like this:

public MyClass GetSomeCachedData(){
            return CacheHelper.GetCached(
                "GetSomeCachedData, () =&gt;
                {

                        return ComputeExpensiveResult();
                }
                }, TimeSpan.FromMinutes(1), Cache.NoAbsoluteExpiration);
}


Do you see any issues?  Can it be improved?

(I'm sticking to .NET 3.5)
Several suggestions:


You could use MemoryCache class as of .NET 4, which would free you from System.Web assembly.
You should use lock in order to put the value to cache.
You should take care of value types objects


So, here is the code:

public static T GetCached&lt;T&gt;(string key, Func&lt;T&gt; initializer, TimeSpan slidingExpiration, DateTime absoluteExpiration)
{
    var httpContext = HttpContext.Current;

    if (httpContext != null)
    {
        key = string.Intern(key); 
        lock(key) // locking on interned key
        {
            var obj = httpContext.Cache[key];
            if (obj == null)
            {
                obj = initializer();
                httpContext.Cache.Add(key, obj, null, absoluteExpiration, slidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
            }
            // taking care of value types
            if (obj == null &amp;&amp; (typeof (T)).IsValueType)
            {
                return default(T);
            }
            return (T)obj;
        }
    }
    else
    {
        return initializer(); // no available cache
    }
}