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

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

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

本文實(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ì)有所幫助。

相關(guān)文章

最新評(píng)論

重庆市| 肃南| 婺源县| 揭东县| 涟水县| 德阳市| 凤凰县| 报价| 大埔县| 沽源县| 秦安县| 阳江市| 应用必备| 巨野县| 泸定县| 东乌珠穆沁旗| 宁明县| 盐池县| 七台河市| 政和县| 如皋市| 蒙阴县| 东乌| 仁布县| 互助| 清涧县| 星座| 莆田市| 墨脱县| 云梦县| 晋州市| 榕江县| 缙云县| 博湖县| 安徽省| 武鸣县| 德阳市| 武清区| 五大连池市| 彩票| 伊金霍洛旗|