• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    ASP.NET缓存处理类实例

    本文实例讲述了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);
      }
    }
    
    

    希望本文所述对大家的asp.net程序设计有所帮助。

    您可能感兴趣的文章:
    • TextArea设置MaxLength属性最大输入值的js代码
    • 通过length属性判断jquery对象是否存在
    • Javascript学习笔记之数组的遍历和 length 属性
    • jQuery对象的length属性用法实例
    • php操作memcache缓存方法分享
    • 在for循环中length值是否需要缓存
    上一篇:ASP.NET创建动态缩略图的方法
    下一篇:浅谈ASP.NET中多层架构
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯 版权所有

    《增值电信业务经营许可证》 苏ICP备15040257号-8

    ASP.NET缓存处理类实例 ASP.NET,缓存,处理,类,实例,