zoukankan      html  css  js  c++  java
  • 学习到的

    一:使用foreach(var item in 数据集) 循环添加到页面利用非服务器控件

    二:地址重写 (利用XML)

    三:利用反射获取数据列(emit获取属性)

    四:单件模式(加锁)

           

       #region 单件模式
            private static EfastServiceDAL dataAccess = null;
            static readonly object padlock = new object();
            public static EfastServiceDAL DataAccess
            {
                get
                {
                    if (dataAccess == null)
                    {
                        lock (padlock)
                        {
                            if (dataAccess == null)
                                dataAccess = new EfastServiceDAL();
                        }
                    }
                    return dataAccess;
                }
            }
            #endregion

    五:缓存的使用(HttpRuntime.Cache)

    六:Dapper(利用emit的一种轻量sql操作方法)

    七:WPF

    八:可视化的log记录(log4net.ElasticSearch.ElasticSearchAppender

    九:支付宝微信支付的调用

           根据订单调用支付宝接口回传给前端数据然后返回得到通知结果支付状态

    十:图片存储在第三方又拍云(将图片上传到又拍云,保存链接到数据库,上传图片也是使用的图片流HttpPostedFileBaseInputStream对象 ,读取对象为BinaryReader 的ReadBytes 转为byte[]发送请求)

          将图片链接转为image流 

          WebRequest imgR = WebRequest.Create(imgurl);
          img = Image.FromStream(imgR.GetResponse().GetResponseStream());

    十一:react前端的应用

    十二:需要对库存锁定避免超卖的情况等

    十三:注册填写账户密码,次数过多则需填写验证码

    十四:关于使用委托和表达式树

    十五:依赖注入

    十六:sql的执行helper

    十七:GraphQL的使用

    十八:多线程和异步的使用

    十九:分页操作

    二十:权限管理

    • 5个等级的缓存
      1. 1级是网络级缓存,缓存在浏览器,CDN以及代理服务器中   (举个例子:每个帮助页面都进行了缓存,访问一个页面的代码非常简单)
      2. 2级是由.net框架 HttpRuntime.Cache完成,在每台服务器的内存中。
      3. 3级Redis,分布式内存键值存储,在多个支撑同一个站点的服务器上共享缓存项。
      4. 4级SQL Server Cache,整个数据库,所有数据都被放到内存中。
      5. 5级SSD。通常只在SQL Server预热后才生效。

    缓存

    由于缓存的页面是以json格式的数据传输给前端调用,缓存为json格式的数据

    使用到了HttpRuntime.Cache来缓存json数据到内存中

       一:先查找是否存在此json文件,若存在则返回此缓存名称内容,若不存在则删除此缓存的内容

               定义为 ActionResult可以返回为 FilePathResult   (写入内存的文件内容) 并赋值给ActionResult

     二:不存在json文件则需要重新查询并重写入内存中,并添加缓存键值

              创建文件目录并在目录中写入文件   将 string 类型的转为  ContentResult类型,在将ContentResult.Content的文件写入,最后返回 FilePathResult (写入内存的文件内容) 并赋值给ActionResult

     

                FileStream fs = null;
                StreamWriter sw = null;
                try
                {
                    fs = new FileStream(file_path, FileMode.Create);//文件的绝对路径
                    sw = new StreamWriter(fs);
                    sw.Write(content);
                }
                catch
                {
    
                }
                finally
                {
                    if (sw != null) //释放
                        sw.Close();
                    if (fs != null)
                        fs.Close();
                }

       添加缓存的这里有一些xml和缓存对应的没明白

       

            public virtual void AddObject(string xpath, object o)
            {
                lock (lockHelper)
                {
                    //当缓存到期时间为0或负值,则不再放入缓存
                    if (cs.TimeOut <= 0) return;
    
                    //整理XPATH表达式信息
                    string newXpath = PrepareXpath(xpath);
                    int separator = newXpath.LastIndexOf("/");
                    //找到相关的组名
                    string group = newXpath.Substring(0, separator);
                    //找到相关的对象
                    string element = newXpath.Substring(separator + 1);
    
                    XmlNode groupNode = objectXmlMap.SelectSingleNode(group);
    
                    //建立对象的唯一键值, 用以映射XML和缓存对象的键
                    string objectId = string.Empty;
    
                    XmlNode node = objectXmlMap.SelectSingleNode(PrepareXpath(xpath));
                    if (node != null)
                    {
                        objectId = node.Attributes["objectId"].Value;
                    }
    
                    if (objectId == "")
                    {
                        groupNode = CreateNode(group);
                        objectId = Guid.NewGuid().ToString();
                        //建立新元素和一个属性 for this perticular object
                        XmlElement objectElement = objectXmlMap.OwnerDocument.CreateElement(element);
                        XmlAttribute objectAttribute = objectXmlMap.OwnerDocument.CreateAttribute("objectId");
                        objectAttribute.Value = objectId;
                        objectElement.Attributes.Append(objectAttribute);
                        //为XML文档建立新元素
                        groupNode.AppendChild(objectElement);
                    }
                    else
                    {
                        //建立新元素和一个属性 for this perticular object
                        XmlElement objectElement = objectXmlMap.OwnerDocument.CreateElement(element);
                        XmlAttribute objectAttribute = objectXmlMap.OwnerDocument.CreateAttribute("objectId");
                        objectAttribute.Value = objectId;
                        objectElement.Attributes.Append(objectAttribute);
                        //为XML文档建立新元素
                        groupNode.ReplaceChild(objectElement, node);
                    }
    
                    //向缓存加入新的对象
                    cs.AddObject(objectId, o);
                }
    
    }
       protected static volatile System.Web.Caching.Cache webCache = System.Web.HttpRuntime.Cache;

    /// <summary> /// 加入当前对象到缓存中 /// </summary> /// <param name="objId">对象的键值</param> /// <param name="o">缓存的对象</param> public virtual void AddObject(string objId, object o) { if (objId == null || objId.Length == 0 || o == null) { return; } //表示永不过期 if (TimeOut == 0) { webCache.Insert(objId, o, null, DateTime.MaxValue, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null); } else { webCache.Insert(objId, o, null, DateTime.Now.AddSeconds(TimeOut), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.High, null); } }

      缓存移除

      将缓存的键值对移除,要用的时候判断删除内存中的文件

    111111
  • 相关阅读:
    解决Tomcat请求中文乱码的问题
    Bootstrap 兼容 IE
    Spring+MyBatis多数据源配置实现
    年度总结与计划
    AJAX 提交表单以及文件上传
    移动端Web开发调试工具:Chrome DevTools
    SpringMVC 之 @ResponseBody 和 @RequestBody
    goland快键键防忘
    MySQL日志文件影响数据库的各种类型活动
    何为云计算
  • 原文地址:https://www.cnblogs.com/whl4835349/p/10600401.html
Copyright © 2011-2022 走看看