zoukankan      html  css  js  c++  java
  • .Net Cache

    在.net中有两个类实现了Cache

    • HttpRuntime.Cache 应该程序使用的Cache,web也可以用
    • HttpContext.Current.Cache  web上下文的Cache对象,只能在Web上使用

    asp.net 页面缓存的封装

      /// <summary>
            /// 根据 cacheKey 获取缓存内容
            /// </summary>
            /// <param name="context">HttpContext</param>
            /// <param name="cacheName">key</param>
            /// <param name="cacheFunc">Func委托,该方法返回结果为要缓存的对象,当存在改缓存时,不会执行该委托的方法</param>
            /// <param name="timeoutHours">单位:小时,默认值为12</param>
            /// <returns>缓存内容</returns>
            public static Object GetCacheByName(HttpContextBase context,string cacheName,Func<object>cacheFunc,int timeoutHours=12)
            {
                if (context.Cache[cacheName] == null)
                {
                    context.Cache.Insert(cacheName, cacheFunc.Invoke(), null, DateTime.Now.AddHours(timeoutHours), Cache.NoSlidingExpiration);
                }
                return context.Cache[cacheName];
            }
    View Code
  • 相关阅读:
    XML Schema (1)
    xml
    java输入输出流(内容练习)
    Java中I/O的分析
    java File类
    java中Map的用法(HaspMap用法)
    Git
    oracle安装分析
    博客第一天
    正则化 L1 L2
  • 原文地址:https://www.cnblogs.com/Blogs-Wang/p/6486832.html
Copyright © 2011-2022 走看看