how to clear cache in asp.nethttp://forums.asp.net/t/1796709.aspx/1?how+to+clear+cache+in+asp+netWed, 02 May 2012 07:42:33 -040017967094950200http://forums.asp.net/p/1796709/4950200.aspx/1?how+to+clear+cache+in+asp+nethow to clear cache in asp.net <p>hi</p> <p>can anyone help? there are lots of discussion and forums on how to clear cache but i can't the one that is working.&nbsp;</p> <p>how &nbsp;can i programatically clear the cache using javascript or C#.net?</p> <p>thanks</p> 2012-04-25T08:18:37-04:004950233http://forums.asp.net/p/1796709/4950233.aspx/1?Re+how+to+clear+cache+in+asp+netRe: how to clear cache in asp.net <p>hi,</p> <p>You can clear cache by using the following code,</p> <pre class="default prettyprint"><pre class="prettyprint">public void ClearApplicationCache(){ List&lt;string&gt; keys = new List&lt;string&gt;(); // retrieve application Cache enumerator IDictionaryEnumerator enumerator = Cache.GetEnumerator(); // copy all keys that currently exist in Cache while (enumerator.MoveNext()){ keys.Add(enumerator.Key.ToString()); } // delete every key from cache for (int i = 0; i &lt; keys.Count; i&#43;&#43;) { Cache.Remove(keys[i]); } }</pre></pre></pre> 2012-04-25T08:32:38-04:004950405http://forums.asp.net/p/1796709/4950405.aspx/1?Re+how+to+clear+cache+in+asp+netRe: how to clear cache in asp.net <p>i tried that already but it's not working with me</p> 2012-04-25T09:48:35-04:004951037http://forums.asp.net/p/1796709/4951037.aspx/1?Re+how+to+clear+cache+in+asp+netRe: how to clear cache in asp.net <p>hi..</p> <p>Try the below code.</p> <pre class="prettyprint">For Each de As DictionaryEntry In HttpContext.Current.Cache HttpContext.Current.Cache.Remove(DirectCast(de.Key, String)) Next</pre> <p><br> <br> </p> 2012-04-25T14:08:32-04:004951040http://forums.asp.net/p/1796709/4951040.aspx/1?Re+how+to+clear+cache+in+asp+netRe: how to clear cache in asp.net <p>Try the above code its working perfectly to remove all the cache&nbsp;</p> 2012-04-25T14:09:02-04:004951703http://forums.asp.net/p/1796709/4951703.aspx/1?Re+how+to+clear+cache+in+asp+netRe: how to clear cache in asp.net <p>i put that part of the code in my upload button so everytime I click the upload file it will clear the cache, right? but&nbsp;its not working... :-(</p> 2012-04-26T00:43:21-04:004951713http://forums.asp.net/p/1796709/4951713.aspx/1?Re+how+to+clear+cache+in+asp+netRe: how to clear cache in asp.net <p>i tried it again and its deleting the cache but i have to close my browser before it take effect :-(</p> 2012-04-26T01:09:37-04:004954474http://forums.asp.net/p/1796709/4954474.aspx/1?Re+how+to+clear+cache+in+asp+netRe: how to clear cache in asp.net <p>Hi,</p> <p>You can try to use HttpRuntime.Close().</p> <p><a href="http://weblogs.asp.net/atlaszhu/archive/2009/03/09/how-to-dynamically-remove-asp-net-page-output-cache-entries.aspx">http://weblogs.asp.net/atlaszhu/archive/2009/03/09/how-to-dynamically-remove-asp-net-page-output-cache-entries.aspx</a></p> <p><a href="http://weblogs.asp.net/morteza/archive/2008/08/11/how-to-remove-all-items-from-cache-memory.aspx">http://weblogs.asp.net/morteza/archive/2008/08/11/how-to-remove-all-items-from-cache-memory.aspx</a></p> 2012-04-27T08:54:39-04:004961113http://forums.asp.net/p/1796709/4961113.aspx/1?Re+how+to+clear+cache+in+asp+netRe: how to clear cache in asp.net <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Richey</h4> <p></p> <p>Hi,</p> <p>You can try to use HttpRuntime.Close().</p> <p><a href="http://weblogs.asp.net/atlaszhu/archive/2009/03/09/how-to-dynamically-remove-asp-net-page-output-cache-entries.aspx">http://weblogs.asp.net/atlaszhu/archive/2009/03/09/how-to-dynamically-remove-asp-net-page-output-cache-entries.aspx</a></p> <p><a href="http://weblogs.asp.net/morteza/archive/2008/08/11/how-to-remove-all-items-from-cache-memory.aspx">http://weblogs.asp.net/morteza/archive/2008/08/11/how-to-remove-all-items-from-cache-memory.aspx</a></p> <p></p> </blockquote> <p></p> <p></p> <p>Hi. Do I have to erase my previous code or I will just add this &quot;HttpRuntime.Close()&quot; after?</p> <p>Below is my code:</p> <pre class="prettyprint">public void ClearApplicationCache() { List&lt;string&gt; keys = new List&lt;string&gt;(); IDictionaryEnumerator enumerator = Cache.GetEnumerator(); while (enumerator.MoveNext()) { keys.Add(enumerator.Key.ToString()); } for (int i = 0; i &lt; keys.Count; i&#43;&#43;) { Cache.Remove(keys[i]); } }</pre> <p>Thanks.&nbsp;<br> <br> </p> 2012-05-02T07:42:33-04:00