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;
}

Comments

Popular posts from this blog

Convert XElement to DataTable

Enable mouse scroll-wheel in VB6

C# code to Check IE Proxy Settings