濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > ASP.NET緩存處理類(lèi)實(shí)例

ASP.NET緩存處理類(lèi)實(shí)例

熱門(mén)標(biāo)簽:400電話辦理最優(yōu)質(zhì) 河北網(wǎng)絡(luò)回?fù)芡夂粝到y(tǒng) 關(guān)于宗地圖標(biāo)注技術(shù)規(guī)范 t3出行地圖標(biāo)注怎么做 威海電銷(xiāo) 河南語(yǔ)音外呼系統(tǒng)公司 寧夏機(jī)器人電銷(xiāo) 外呼電銷(xiāo)機(jī)器人軟件 400免費(fèi)電話怎么辦理

本文實(shí)例講述了ASP.NET緩存處理類(lèi)。分享給大家供大家參考。具體如下:
ASP.NET 緩存處理類(lèi)。

用法:

Just copy this code into a new class file (.cs) and add it to your ASP .NET website. One thing to keep in mind is that data stored in ASP .NET Cache can be accessible across all sessions. So when creating a cacheID for the object to be stored, it must be unique (or it could be overwritten). I usually store the unique cacheID in the session and then use that to referrence the cacheID. (e.g. CacheHandler.Write(Session["MyCacheData"], myData);)

具體代碼如下:

using System;
using System.Collections.Generic;
using System.Web.Caching;
using System.Web;
/// summary>
/// This class reads/writes to ASP .NET server cache. For the sake of 
/// simplicity, the class writes objects to cache with no expirateion.
/// Use the Remove() function to programmatically remove objects stored
/// from the server cache. This class was created as an alternative to 
/// storing large objects in the session.
/// /summary>
public class CacheHandler
{
  public static bool Write(string cacheID, object data)
  {
    if (HttpContext.Current == null)
      return false;
    if (cacheID == null || cacheID.Equals(""))
      return false;
    HttpRuntime.Cache.Insert(
        cacheID, data, null, Cache.NoAbsoluteExpiration, 
        Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null
        );
    return true;
  }
  public static object Read(string cacheID)
  {
    if (HttpContext.Current == null)
      return null;
    return HttpRuntime.Cache.Get(cacheID);
  }
  public static void Remove(string cacheID)
  {
    if (HttpContext.Current == null )
      return;
    if (cacheID == null || cacheID.Equals(""))
      return;
    HttpRuntime.Cache.Remove(cacheID);
  }
}

希望本文所述對(duì)大家的asp.net程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • TextArea設(shè)置MaxLength屬性最大輸入值的js代碼
  • 通過(guò)length屬性判斷jquery對(duì)象是否存在
  • Javascript學(xué)習(xí)筆記之?dāng)?shù)組的遍歷和 length 屬性
  • jQuery對(duì)象的length屬性用法實(shí)例
  • php操作memcache緩存方法分享
  • 在for循環(huán)中l(wèi)ength值是否需要緩存

標(biāo)簽:賀州 吉林 樂(lè)山 池州 固原 淮北 咸寧 廣元

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET緩存處理類(lèi)實(shí)例》,本文關(guān)鍵詞  ASP.NET,緩存,處理,類(lèi),實(shí)例,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP.NET緩存處理類(lèi)實(shí)例》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于ASP.NET緩存處理類(lèi)實(shí)例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    桐柏县| 富顺县| 瓮安县| 阳信县| 大关县| 大理市| 成都市| 三明市| 专栏| 龙口市| 太谷县| 驻马店市| 新巴尔虎左旗| 固安县| 广汉市| 徐州市| 咸丰县| 宽城| 新民市| 治县。| 施甸县| 南投市| 武清区| 巴彦淖尔市| 洪江市| 利川市| 孟津县| 黄梅县| 平原县| 深圳市| 通山县| 辽宁省| 宕昌县| 上饶县| 延边| 桐柏县| 天津市| 尼勒克县| 德州市| 广元市| 普兰县|