开发者

Force all ASP.NET cache to expire

开发者 https://www.devze.com 2022-12-30 23:45 出处:网络
Is there a method or something to force the expiration of all of 开发者_高级运维the entries in the Cache collection of the HttpContext?Try something like this:

Is there a method or something to force the expiration of all of 开发者_高级运维the entries in the Cache collection of the HttpContext?


Try something like this:

var enumerator = HttpRuntime.Cache.GetEnumerator();
Dictionary<string, object> cacheItems = new Dictionary<string, object>();

while (enumerator.MoveNext())
    cacheItems.Add(enumerator.Key.ToString(), enumerator.Value);

foreach (string key in cacheItems.Keys)
    HttpRuntime.Cache.Remove(key);


what about updating the cache to expire ?

protected void btnClearCache_Click(object sender, EventArgs e)
{

    var enumerator = HttpRuntime.Cache.GetEnumerator();

    while (enumerator.MoveNext())
        HttpRuntime.Cache.Insert(enumerator.Key.ToString(), enumerator.Value, 
            null, DateTime.Now , Cache.NoSlidingExpiration);
}
0

精彩评论

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