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();
  • 相关阅读:
    Windows Phone 7 ManipulationStarted 事件
    用C#实现AES加密和解密
    Windows Phone 7 程序菜单栏ApplicationBar
    Windows Phone 7 使用选择器(Chooser)
    Windows Phone 7 矢量图形编程
    Windows Phone 7 位图BitmapImage和WriteableBitmap
    Windows Phone 7 利用计时器DispatcherTimer创建时钟
    Windows Phone 7 配置文件WMAppmanifest.xml的介绍
    C#转换人民币大小金额
    Windows Phone 7 入门XAML语法介绍
  • 原文地址:https://www.cnblogs.com/New-world/p/3168581.html
Copyright © 2011-2022 走看看