最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2015年06月16日 10:47:40   作者:小卒過(guò)河  
這篇文章主要介紹了ASP.NET緩存處理類,實(shí)例分析了asp.net緩存的使用技巧,需要的朋友可以參考下

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

用法:

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ì)有所幫助。

相關(guān)文章

最新評(píng)論

岚皋县| 太保市| 麟游县| 贵德县| 丽水市| 外汇| 贵德县| 廊坊市| 蛟河市| 黄龙县| 常山县| 恩平市| 博乐市| 丹阳市| 衡山县| 黄平县| 霞浦县| 鹿泉市| 德清县| 清远市| 丽水市| 八宿县| 阳谷县| 噶尔县| 瑞金市| 丰宁| 张家口市| 商洛市| 襄城县| 岳池县| 虞城县| 黄梅县| 沂源县| 江永县| 新闻| 包头市| 电白县| 阿鲁科尔沁旗| 玉林市| 永城市| 蚌埠市|