zoukankan      html  css  js  c++  java
  • .net 缓存之应用程序数据缓存

    CaCheHelp类中代码如下:

            #region 根据键从缓存中读取保持的数据
            /// <summary>
            /// 根据键从缓存中读取保持的数据
            /// </summary>
            /// <param name="CaCheKey">索引键值</param>
            /// <returns></returns>
            public static object GetCaChe(string CaCheKey)
            {
                System.Web.Caching.Cache ca = HttpRuntime.Cache;
                return ca[CaCheKey];
            } 
            #endregion
    
            #region 设置当前应用程序中指定的缓存项
            /// <summary>
            /// 设置当前应用程序中指定的缓存项
            /// </summary>
            /// <param name="CaCheKey">索引键值</param>
            /// <param name="objValue">缓存对象</param>
            public static void SetCaChe(string CaCheKey, object objValue)
            {
                System.Web.Caching.Cache ca = HttpRuntime.Cache;
                ca.Insert(CaCheKey, objValue);
            } 
            #endregion
    
            #region 设置当前应用程序中指定的缓存项  重载
            /// <summary>
            /// 设置当前应用程序中指定的缓存项  重载
            /// </summary>
            /// <param name="CaCheKey">索引键值</param>
            /// <param name="objValue">缓存对象</param>
            /// <param name="ab">绝对过期时间</param>
            /// <param name="sp">最后一次访问所插入对象时与该对象过期时之间的时间间隔<</param>
            public static void SetCaChe(string CaCheKey, object objValue, DateTime ab, TimeSpan sp)
            {
                System.Web.Caching.Cache ca = HttpRuntime.Cache;
                ca.Insert(CaCheKey, objValue, null, ab, sp);
            } 
            #endregion

    页面调用代码:

    string CaCheKey = "cachekey";
                object objModel = CaCheHelp.GetCaChe(CaCheKey);
                if (objModel == null)
                {
                    objModel = DateTime.Now; //缓存对象:当前系统时间
                    if (objModel != null)
                    {
                        int CaCheTime = 5; //五秒
                        CaCheHelp.SetCaChe(CaCheKey, objModel, DateTime.Now.AddSeconds(CaCheTime), TimeSpan.Zero);
                    }
                }
                
                lable_time.InnerText = objModel.ToString();
  • 相关阅读:
    ubuntu安装mysql并使用Navicat连接
    二叉树基础知识点
    Javascript 16进制转有符号的10进制整数
    Node.js 学习笔记(二)
    API测试如何演变为应用程序开发的常规部分
    API在线文档
    API文档自动生成的方法
    快速对比API版本
    如何使用OPENAPI进行质量检查
    【分享】什么是API网关?大公司为什么都有API网关?
  • 原文地址:https://www.cnblogs.com/New-world/p/3168581.html
Copyright © 2011-2022 走看看