• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ASP.NET > ASP.NET缓存处理类实例

ASP.NET缓存处理类实例

作者:小卒过河 字体:[增加 减小] 来源:互联网 时间:2017-05-11

小卒过河通过本文主要向大家介绍了c asp.net实例,用实例学asp.net,ajax实例 asp.net,asp.net,asp net培训等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

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

</div>

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

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • ASP.NET数据库操作类实例
  • ASP.NET导出word实例
  • asp.net反射简单应用实例
  • ASP.NET中的C#基础知识
  • asp.net core mvc实现文件上传实例
  • ASP.NET Core 导入导出Excel xlsx 文件实例
  • Asp.net中安全退出时清空Session或Cookie的实例代码
  • asp.net保存网上图片到服务器的实例
  • asp.net多文件上传实例讲解
  • ASP.Net分页的分页导航实例

相关文章

  • 2017-05-11关于有些Asp.net项目发布后出现网址乱码的解决方法
  • 2017-05-11FileStreaReder和StreamReader两个类介绍
  • 2017-05-11ASPX中的用户控件与ASP中的INCLUDE方法对比
  • 2017-05-11ASP.NET实现基于Forms认证的WebService应用实例
  • 2017-05-11详解ASP.NET WEB API 之属性路由
  • 2017-05-11asp.net String.format中大括号的加入方法
  • 2017-05-11Visual Studio ASP.NET Core MVC入门教程第一篇
  • 2017-05-11Repeater控件实现编辑、更新、删除等操作示例代码
  • 2017-05-11asp.net中资源文件的使用
  • 2017-05-11asp.net 用户控件中图片及样式问题

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • .net 通过URL推送POST数据具体实现
    • asp.net中Null在从数据库读取的时候的一点点小技巧
    • ASP.NET从字符串中查找字符出现次数的具体实现方法
    • 在程序中使用Cookie集合(定义/新建/删除)及案例讲解
    • 验证用户必选CheckBox控件与自定义验证javascript代码
    • 为T-SQL添加intellisense功能
    • asp.net url 伪静态设置方法
    • Visual Studio 2017设置版权的方法
    • ASP.NET 前台javascript与后台代码调用
    • asp.net 分页sql语句(结合aspnetpager)

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有