zoukankan      html  css  js  c++  java
  • 服务器缓存帮助类

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Web;

    using System.Collections;

    using System.Web.Caching;

    namespace AIMSCommon {     /// <summary>     /// 服务器缓存帮助类     /// </summary>     public class CacheHelper     {         /// <summary>         /// 创建缓存项的文件依赖         /// </summary>         /// <param name="key">缓存Key</param>         /// <param name="obj">object对象</param>         /// <param name="fileName">文件绝对路径</param>         public static void InsertFile(string key, object obj, string fileName)         {             //创建缓存依赖项             CacheDependency dep = new CacheDependency(fileName);             //创建缓存             HttpContext.Current.Cache.Insert(key, obj, dep);         }

            /// <summary>         /// 创建缓存项过期         /// </summary>         /// <param name="key">缓存Key</param>         /// <param name="obj">object对象</param>         public static void Insert(string key, object obj)         {             if (obj !=null)             {                 int expires = CommonHelper.GetInt(ConfigHelper.GetAppSettings("TimeCache"));                 HttpContext.Current.Cache.Insert(key, obj, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, expires, 0));             }         }         /// <summary>         /// 判断缓存对象是否存在         /// </summary>         /// <param name="strKey">缓存键值名称</param>         /// <returns>是否存在true 、false</returns>         public static bool IsExist(string strKey)         {             return HttpContext.Current.Cache[strKey] != null;         }         /// <summary>         /// 获取缓存对象         /// </summary>         /// <param name="key">缓存Key</param>         /// <returns>object对象</returns>         public static object GetCache(string key)         {             if (string.IsNullOrEmpty(key))                 return null;             if (ConfigHelper.GetAppSettings("IsCache") == "false")             {                 return null;             }             return HttpContext.Current.Cache.Get(key);         }

            /// <summary>         /// 获取缓存对象         /// </summary>         /// <typeparam name="T">T对象</typeparam>         /// <param name="key">缓存Key</param>         /// <returns></returns>         public static T Get<T>(string key)         {             object obj = GetCache(key);             return obj == null ? default(T) : (T)obj;         }

            /// <summary>         /// 移除指定数据缓存         /// </summary>         public static void RemoveAllCache(string CacheKey)         {             System.Web.Caching.Cache _cache = HttpRuntime.Cache;             _cache.Remove(CacheKey);         }

            /// <summary>         /// 移除全部缓存         /// </summary>         public static void RemoveAllCache()         {             System.Web.Caching.Cache _cache = HttpRuntime.Cache;             IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();             while (CacheEnum.MoveNext())             {                 _cache.Remove(CacheEnum.Key.ToString());             }         }     } }

  • 相关阅读:
    SiteMap 提交,并使用正确的方式提交给搜索引擎
    爱自己的人脸上散发的光芒是骗不了别人的,你会活在平静淡定喜悦中,绝少埋怨,鲜有不满,没有太多话需要澄清,说清楚,内心是一片宁静而有力量的海。
    PHP 调用webService方式
    Oracle数据库操作知道
    气泡 弹出 bootstrap-popover的配置与灵活应用
    mysql向表中某字段后追加一段字符串:
    LINUX 下安装一些东西,PHP Apach SSL 等
    在同一个页面上要使用多个百度分享,控件人分享的内容信息
    Linux study
    Mysql 备份
  • 原文地址:https://www.cnblogs.com/zhangxiaolei521/p/5660769.html
Copyright © 2011-2022 走看看