zoukankan      html  css  js  c++  java
  • 缓存类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using MyBlog.Linq;
    using System.Configuration;
    using MyBlog.BLL;
     
    namespace MyBlog.UI
    {
        /// <summary>
        /// 缓存类
        /// </summary>
        public static class CacheData
        {
            /// <summary>
            /// 获取数据上下文,该属性可以保证每个请求仅生成一个数据上下文对象
            /// </summary>
            private static DBDataContext dc
            {
                get
                {
                    if (HttpContext.Current.Items["dc"] == null)
                    {
                        DBDataContext _dc = new DBDataContext(ConfigurationManager.ConnectionStrings["myblog"].ConnectionString);
                        HttpContext.Current.Items.Add("dc", _dc);
                    }
                    return (DBDataContext)HttpContext.Current.Items["dc"];
                }
            }
     
            /// <summary>
            /// 获取UserManager对象,该属性可以保证每个请求仅生成一个UserManager对象
            /// </summary>
            public static UserManager UM
            {
                get
                {
                    if (HttpContext.Current.Items["UM"] == null)
                    {
                        HttpContext.Current.Items.Add("UM", new UserManager(dc));
                    }
                    return (UserManager)HttpContext.Current.Items["UM"];
                }
            }
     
            /// <summary>
            /// 获取当前登录用户,若没有登录则为null,该属性可以保证每个请求仅生成一个BlogUser对象
            /// </summary>
            public static BlogUser LoginUser
            {
                get
                {
                    if (HttpContext.Current.Items["U"] == null)
                    {
                        string name = HttpContext.Current.User.Identity.Name;
                        if (string.IsNullOrEmpty(name))
                        {
                            HttpContext.Current.Items.Add("U", "-1");
                        }
                        else
                        {
                            int id = Convert.ToInt32(name);
                            HttpContext.Current.Items.Add("U",UM.GetUserByID(id));
                        }
                    }
                    if (HttpContext.Current.Items["U"] is BlogUser)
                    {
                        return (BlogUser)HttpContext.Current.Items["U"];
                    }
                    else
                    {
                        return null;
                    }
                }
     
            }
     
            /// <summary>
            /// 获取TypeManager对象,该属性可以保证每个请求仅生成一个TypeManager对象
            /// </summary>
            public static TypeManager TM
            {
                get
                {
                    if (HttpContext.Current.Items["TM"] == null)
                    {
                        HttpContext.Current.Items.Add("TM", new TypeManager(dc));
                    }
                    return (TypeManager)HttpContext.Current.Items["TM"];
                }
            }
     
            /// <summary>
            /// 获取ArticlManager对象,该属性可以保证每个请求仅生成一个ArticlManager对象
            /// </summary>
            public static ArticlManager AM
            {
                get
                {
                    if (HttpContext.Current.Items["AM"] == null)
                    {
                        HttpContext.Current.Items.Add("AM", new ArticlManager(dc));
                    }
                    return (ArticlManager)HttpContext.Current.Items["AM"];
                }
     
            }
        }
    }
  • 相关阅读:
    CentOS 上配置 lua 的服务器环境(enet)
    报错解决 unable to unroll loop, loop does not appear to terminate in a timely manner (994 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number
    开源许可证的选择
    Lua 协程
    [命令模式]在游戏开发中的应用
    NGUI 源码分析- AnchorPoint
    NGUI 源码分析- UIWidgetInspector
    Java程序员需要学习的知识点
    Linux下安装Perl和Perl的DBI模块
    Linux安装JDK
  • 原文地址:https://www.cnblogs.com/superMay/p/4097442.html
Copyright © 2011-2022 走看看