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"];
                }
     
            }
        }
    }
  • 相关阅读:
    超棒的微软Metro风格Logo设计
    免费资源:Polaris UI套件 + Linecons图标集(AI, PDF, PNG, PSD, SVG)
    11套免费的wordpress模板主题
    SASS(Syntactically Awesome Stylesheets Sass)绝对新手入门教程
    分享网页加载速度优化的一些技巧?
    帮助开发者快速创建响应式布局的Boilerplate Responsive Boilerplate
    免费素材: Retina Glyph图标集 (包含100个AI & PNG格式的图标)
    响应式的前端框架 Groundwork
    帮助你搜索免费矢量,图标和PSD的搜索引擎 Freepik
    Toolbar.Js 帮助你创建提示风格的工具条jQuery插件
  • 原文地址:https://www.cnblogs.com/superMay/p/4097442.html
Copyright © 2011-2022 走看看