Wednesday, March 13, 2013

Filling, Fetching and Removing HttpRuntime.Cache

public static void FillCache(string strCacheKey, object cacheObject)
{
    HttpRuntime.Cache.Insert(strCacheKey, cacheObject, null, DateTime.MaxValue, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, null);
}

public static object GetCache(string cacheKey)
{
    object cacheObject = null;
    if (HttpRuntime.Cache[cacheKey] != null)
    {
        cacheObject = HttpRuntime.Cache[cacheKey];
    }
    return cacheObject;
}

public static bool RemoveCache(string cacheKey)
{
    bool isRemoved = false;
    if (HttpRuntime.Cache[cacheKey] != null)
    {
        HttpRuntime.Cache.Remove(cacheKey);
        isRemoved = true;
    }
    return isRemoved;
}

No comments:

Post a Comment