开发者

Completely clean up cache in asp.net mvc application

开发者 https://www.devze.com 2023-04-04 04:04 出处:网络
Is it possible to clear asp.net cache? Is there different ways to do that? For example is it possible to do that on IIS(7.5) side? Is it possible to do by selecting the application i want to clear ca

Is it possible to clear asp.net cache? Is there different ways to do that?

For example is it possible to do that on IIS(7.5) side? Is it possible to do by selecting the application i want to clear cache in on IIS manager console? IIS i have one option to do that - application restart which is basically doin开发者_C百科g more than that but i want just clear the cache, may be there is any IIS extensions which doing that?

Should i write the code to do that for example from admin part of web site?


Here is a code that cleans up the Application Cache from Application side. I dont know of a way cleaning it from IIS.

public void ClearApplicationCache()
{
    List<string> keys = new List<string>();

    // 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 < keys.Count; i++)
    {
        Cache.Remove(keys[i]);
    }
}

Now just make a page for that or a button to call that from Admin Panel :)

Good Luck.

Taken From: aspdotnetfaq.com

0

精彩评论

暂无评论...
验证码 换一张
取 消