好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Asp.Net中Cache操作類實例詳解

Asp.Net中Cache操作類實例詳解

熱門標簽:400電話如何申請取消 征途美甲店地圖標注 昆明語音電銷機器人價格 柳州電銷機器人公司 騰訊地圖標注手機 百度地圖怎樣做地圖標注 浦發電話機器人提醒還款 電銷語音機器人型號參數 太原400電話上門辦理

本文以一個Asp.Net的Cache操作類實例代碼來詳細描述了cache緩存的結構及實現方法,完整代碼如下所示:

/// head>
/// function>
///  存儲類(存儲UserInfo信息)
/// /function>
/// description>
///  用Cache存儲用戶信息
///  在指定間隔(TimeOut)內取,則可以從Cache中取,
///  如果超出存儲時間,則從數據庫取用戶信息數據
///  作為所有用戶信息的存儲類.
/// /description>
/// author>
///  name>ChengKing/name>  
/// /author>
/// /head>
using System;
using System.Web;
using System.Web.Caching;
namespace Common
{   
 /// summary>
 /// 存儲類(存儲UserInfo信息)
 /// /summary>
 public class Storage
 {
 public Storage()
 {
  //
  // TODO: 在此處添加構造函數邏輯
  //
 }
 #region 方法
 //實現“一鍵一值”存儲方法,最普通的存儲方法  
        //(“一鍵一值”指一個Identify存儲一個值,下面還有一個“一鍵多值”方法,因為有時候需要一個鍵存儲多個變量對象值)
        public static bool InsertIdentify(string strIdentify,object Info)
 {  
  if(strIdentify != null  strIdentify.Length != 0  userInfo != null)
  {
  //建立回調委托的一個實例
    CacheItemRemovedCallback callBack =new CacheItemRemovedCallback(onRemove);
  //以Identify為標志,將userInfo存入Cache
  HttpContext.Current.Cache.Insert(strIdentify,userInfo,null, 
        System.DateTime.Now.AddSeconds(300),
        System.Web.Caching.Cache.NoSlidingExpiration, 
        System.Web.Caching.CacheItemPriority.Default,
        callBack);
  return true;
  }  
  else
  {
  return false;
  }
 }
 //判斷存儲的"一鍵一值"值是否還存在(有沒有過期失效或從來都未存儲過)
      public static bool ExistIdentify(string strIdentify)
 {
  if(HttpContext.Current.Cache[strIdentify] != null)
  {
  return true;
  }
  else
  {
  return false;
  }
 }
 //插入"一鍵多值"方法
 //***其中 StorageInfType是一個Enum,里面存有三種類型: UserInf SysInf PageInf 
 //這個枚舉如下:
 /*
      public enum StorageInfType
      {
    /// summary>用戶信息/summary>
      UserInf = 0,
    /// summary>頁面信息/summary>
    PageInf = 1, 
    /// summary>系統信息/summary>
        SysInf = 2
       }
        //此枚舉是自己定義的.可根據需要定義不同的枚舉 
        //加個枚舉目的是實現“一鍵多值”存儲方法,事實上Cache中是存放了多個變量的,只不過被這個類封裝了,
        //程序員感到就好像是“一鍵一值”.  這樣做目的是可以簡化開發操作,否則程序員要存儲幾個變量就得定義幾個Identify.
 public static bool InsertCommonInf(string strIdentify,StorageInfType enumInfType,object objValue)
 {  
  if(strIdentify != null  strIdentify != ""  strIdentify.Length != 0  objValue != null)
  {
  //RemoveCommonInf(strIdentify,enumInfType); 
  //建立回調委托的一個實例
        CacheItemRemovedCallback callBack =new CacheItemRemovedCallback(onRemove);
  if(enumInfType == StorageInfType.UserInf)
  {  
    //以用戶UserID+信息標志(StorageInfType枚舉),將userInfo存入Cache
    HttpContext.Current.Cache.Insert(strIdentify+StorageInfType.UserInf.ToString(),objValue,null, 
         System.DateTime.Now.AddSeconds(18000),    //單位秒
         System.Web.Caching.Cache.NoSlidingExpiration, 
         System.Web.Caching.CacheItemPriority.Default,
         callBack); 
  }
  if(enumInfType == StorageInfType.PageInf)
  {
   //以用戶UserID+信息標志(StorageInfType枚舉),將PageInfo存入Cache
     HttpContext.Current.Cache.Insert(strIdentify+StorageInfType.PageInf.ToString(),objValue,null, 
          System.DateTime.Now.AddSeconds(18000),
          System.Web.Caching.Cache.NoSlidingExpiration, 
          System.Web.Caching.CacheItemPriority.Default,
          callBack); 
  }
  if(enumInfType == StorageInfType.SysInf)
  {
   //以用戶UserID+信息標志(StorageInfType枚舉),將SysInfo存入Cache
   HttpContext.Current.Cache.Insert(strIdentify+StorageInfType.SysInf.ToString(),objValue,null, 
          System.DateTime.Now.AddSeconds(18000),
           System.Web.Caching.Cache.NoSlidingExpiration, 
          System.Web.Caching.CacheItemPriority.Default,
          callBack); 
  }
  return true;
  }
  return false;
 }
        //讀取“一鍵多值”Identify的值
        public static bool ReadIdentify(string strIdentify,out UserInfo userInfo)
 {
  //取出值
  if((UserInfo)HttpContext.Current.Cache[strIdentify] != null)
  {
  userInfo = (UserInfo)HttpContext.Current.Cache[strIdentify];
  if(userInfo == null)
  {
   return false;
  }
  return true;
  }  
  else
  {
  userInfo = null;
  return false;
  }  
 }
 //手動移除“一鍵一值”對應的值
        public static bool RemoveIdentify(string strIdentify)
 {
  //取出值
  if((UserInfo)HttpContext.Current.Cache[strIdentify] != null)
  {
  HttpContext.Current.Cache.Remove(strIdentify);    
  }  
  return true; 
 }
        //此方法在值失效之前調用,可以用于在失效之前更新數據庫,或從數據庫重新獲取數據
 private static void onRemove(string strIdentify, object userInfo,CacheItemRemovedReason reason)
 {
 }
 #endregion
 } 
}

您可能感興趣的文章:
  • asp.net(C#)遍歷memcached緩存對象
  • Asp.Net Cache緩存使用代碼
  • .net/c# memcached緩存獲取所有緩存鍵的方法步驟
  • ASP.NET OutputCache詳解
  • asp.net中Session緩存與Cache緩存的區別分析
  • ASP.NET中Application和Cache的區別分析
  • .net清空所有Cache的實現代碼
  • ASP.NET Cache的一些總結分享
  • asp.net 使用駐留在頁面中的Cache緩存常用可定時更新的數據
  • .net如何使用Cache框架給程序添加Cache

標簽:陽泉 天門 德陽 新疆 張家界 蘭州 江蘇 白山

巨人網絡通訊聲明:本文標題《Asp.Net中Cache操作類實例詳解》,本文關鍵詞  Asp.Net,中,Cache,操作,類,實例,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Asp.Net中Cache操作類實例詳解》相關的同類信息!
  • 本頁收集關于Asp.Net中Cache操作類實例詳解的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 日本娇小体内?精汇编| 国产大尺度电影吻戏床戏片段| 日韩欧美成人| 久久一本一区二区三区| 隔壁老王国产在线精品| 伦乱大杂烩| 午夜免费视频国产| 女人被啪到高潮gif动态图| 欧美日韩国产精品一区| 双腿大开在校花体内自由进小说| 元套内谢少妇毛片免费看| 青青青国产依人在在线观看高| 九九国产| 毛片网站有哪些| 床吻摸腿中间吃胸故事| 男生操女生动态图| 欧美阿v| 久久久国产免费影院| 女的扒开尿口让男人桶爽| 男人的天堂a在线| 97久久草草超级碰碰碰| 黑寡妇电影完整版1080| 一二三四免费观看完整版高清视频| 瑜伽巜做爰在线观看| 和闺蜜香蕉在ktv被调教| 姐妹秘密换夫| 久久久久中精品中文字幕19| 女人操女人逼| 无码欧美人的又黑又黄的AV| 欧美成人xx禁片在线观看| 欧美黄毛精品一区二区三区免费| 免费国偷拍精品视频| 日本午夜福利片| 欧美????ZZZ物交| 五月综合缴情综合小说欧美AV | 亚洲一区二区三区四区五区福利 | 无码亚洲AV日韩美AⅤ最新 | 国产精品二| 粉嫩的极品女神尤物在线观看| 麻豆国产AV精品一区| 抖淫在线观看|