Pages

Friday, 21 February 2014

Cache key. in dictionary

HttpContext.Current.Cache.Insert("User1", "hi");
        HttpContext.Current.Cache.Insert("User2", "hi");
        HttpContext.Current.Cache.Insert("User3", "hi");
        var array = (from System.Collections.DictionaryEntry dict in HttpContext.Current.Cache
                     let key = dict.Key.ToString()
                     select new
                     {
                         key
                     }).ToArray();
        foreach (var a in array)
        {
            Cache.Remove(a.key);
            if (a.key == "User1")
            {
                Response.Write("<script>alert('hi');</script>");
            }
        }

        DataTable dt = new DataTable();
        dt.Columns.Add("CACHE");
        for (int temp = 0; temp < array.Length; temp++)
        {
            dt.Rows.Add();
            dt.Rows[temp]["CACHE"] = array[temp].ToString();
        }

        GridView1.DataSource = dt;
        GridView1.DataBind();

    }

--

No comments:

Post a Comment