清除Cache缓存

news/2025/2/1 17:55:06/


/// <summary>
/// 清除所有Cache缓存/// </summary>
public static void RemoveAllCache()
{try{Cache _cache = HttpRuntime.Cache;//获取当前运行程序的System.Web.Caching.Cache//枚举非泛型字典的元素IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();//检索用于循环访问包含在缓存中的键设置及其值的字典枚举数while (CacheEnum.MoveNext()){string _key = CacheEnum.Key.ToString();_cache.Remove(_key);}}catch { }
}
/// <summary>
/// 移除缓存的对象
/// </summary>
public static object Remove(string key)
{
</span>//当前Cache对象
System.Web.Caching.Cache webCache = System.Web.HttpRuntime.Cache;lock (CacheLocker)
{
<span style="white-space:pre">	</span>return webCache.Remove(key);
}/// <summary>
/// 清除所有缓存
/// </summary>
public static void RemoveAll()
{
<span style="white-space:pre">	</span>//当前Cache对象           
<span style="white-space:pre">	</span>var cache = System.Web.HttpRuntime.Cache;
<span style="white-space:pre">	</span>foreach (DictionaryEntry de in cache)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>string key = de.Key as string;
<span style="white-space:pre">		</span>cache.Remove(key);
<span style="white-space:pre">	</span>}
}/// <summary>
/// 清除所有与Key相关的缓存
/// </summary>
public static void RemoveAllLike(string keypattern)
{
<span style="white-space:pre">	</span>//当前Cache对象           
<span style="white-space:pre">	</span>var cache = System.Web.HttpRuntime.Cache;
<span style="white-space:pre">	</span>foreach (DictionaryEntry de in cache)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>string key = de.Key as string;
<span style="white-space:pre">		</span>if(key.Contains(keypattern))
<span style="white-space:pre">			</span>cache.Remove(key);
<span style="white-space:pre">	</span>}
/// <summary>
/// Cache插入锁
/// </summary>
private static object CacheLocker = new object();

http://www.ppmy.cn/news/489445.html

相关文章

清除服务器缓存办法

清除服务器缓存办法//在ashx文件中写方法 /// <summary>/// ServerMgr 的摘要说明/// </summary>public class ServerMgr : IHttpHandler{public void ProcessRequest(HttpContext context){object returnObj "";string method context.Request["…

清除cache

总有很多朋友对于Linux的内存管理有疑问&#xff0c;之前一篇[转]理解Linux的性能日志似乎也没能清除大家的疑虑。而在新版核心中&#xff0c;似乎对这个问题提供了新的解决方法&#xff0c;特转出来给大家参考一下。最后&#xff0c;还附上我对这方法的意见&#xff0c;欢迎各…

linux清除cache的2种方法

今天去面试&#xff0c;被问到linux下如何清除cache&#xff0c;一脸懵逼&#xff0c;因为是真的不知道&#xff0c;但记得用sync命令可以把内存中的数据写入硬盘&#xff0c;就这样说了&#xff0c;面试的技术好像不满意&#xff0c;下来之后查了查&#xff0c;原来还有/proc/…

清除linux中缓存(Cache)

每个 Linux 系统有三种选项来清除缓存而不需要中断任何进程或服务。 &#xff08;LCTT 译注&#xff1a;Cache&#xff0c;译作“缓存”&#xff0c;指 CPU 和内存之间高速缓存。Buffer&#xff0c;译作“缓冲区”&#xff0c;指在写入磁盘前的存储再内存中的内容。在本文中&a…

disk cache(磁盘缓存) 和 memory cache(内存缓存)的区别

disk cache(磁盘缓存) 和 memory cache(内存缓存)的区别 同&#xff1a; 都属于强缓存&#xff0c;现在浏览器缓存存储图像和网页等(主要在磁盘上)&#xff0c;而你的操作系统缓存文件可能大部分在内存缓存中。使用这两个缓存功能&#xff0c;是因为它比从远程的 web 服务器获…

Linux如何清除系统cache

1. drop_caches 在Documentation/sysctl/vm.txt中有如下描述: drop_caches Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free. To free pagecache: echo 1 > /proc/sys/vm/drop_cac…

浏览器Disk Cache磁盘缓存及其协商缓存、及原生App和浏览器实现缓存的差异

浏览器Disk Cache磁盘缓存及其协商缓存、及原生App和浏览器实现缓存的差异 目录 浏览器Disk Cache磁盘缓存及其协商缓存、及原生App和浏览器实现缓存的差异 1、Memory Cache和Disk Cache区别 1.1、Memory Cache 1.2、Disk Cache 1.2.1、Disk Cache的存取举例 1.2.2、Dis…

python selenium2/webdriver自动化测试系列教程!?

以下是 Python Selenium2/WebDriver 自动化测试系列教程&#xff0c;希望能对您有所帮助&#xff1a; 1、安装 Selenium WebDriver 在安装 Python 的基础上&#xff0c;请使用 pip 命令安装 Selenium WebDriver&#xff1a; pip install selenium 2、配置浏览器驱动程序 S…