当前位置: 首页 > news >正文

凡科网站建站济南做网站的公司有哪些

凡科网站建站,济南做网站的公司有哪些,任县附近网站建设价格,淘宝关键词搜索量查询ASP.NET的输出缓存#xff08;即静态HTML#xff09;在.NET4.0前一直是基于内存的。这意味着如果我们的站点含有大量的缓存#xff0c;则很容易消耗掉本机内存。现在#xff0c;借助于.NET4.0中的OutputCacheProvider#xff0c;我们可以有多种选择创建自己的缓存。如即静态HTML在.NET4.0前一直是基于内存的。这意味着如果我们的站点含有大量的缓存则很容易消耗掉本机内存。现在借助于.NET4.0中的OutputCacheProvider我们可以有多种选择创建自己的缓存。如我们可以把HTML输出缓存存储到memcached分布式集群服务器或者MongoDB中一种常用的面向文档数据库不妨阅读本篇http://msdn.microsoft.com/zh-cn/magazine/gg650661.aspx。当然我们也可以把缓存作为文件存储到硬盘上考虑到可扩展性这是一种最廉价的做法本文就是介绍如果构建自定义文件缓存。 1OutputCacheProvider OutputCacheProvider是一个抽象基类我们需要override其中的四个方法它们分别是 Add 方法将指定项插入输出缓存中。 Get 方法返回对输出缓存中指定项的引用。 Remove 方法从输出缓存中移除指定项。 Set 方法将指定项插入输出缓存中如果该项已缓存则覆盖该项。 2创建自己的文件缓存处理类 该类型为FileCacheProvider代码如下 public class FileCacheProvider : OutputCacheProvider  {  private static readonly ILog log  LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);   public override void Initialize(string name, NameValueCollection attributes)  {  base.Initialize(name, attributes);  CachePath  HttpContext.Current.Server.MapPath(attributes[cachePath]);  }  public override object Add(string key, object entry, DateTime utcExpiry)  {  Object obj  Get(key);  if (obj ! null) //这一步很重要  {  return obj;  }  Set(key,entry,utcExpiry);  return entry;  }  public override object Get(string key)  {  string path  ConvertKeyToPath(key);  if (!File.Exists(path))  {  return null;  }  CacheItem item  null;  using (FileStream file  File.OpenRead(path))  {  var formatter  new BinaryFormatter();  item  (CacheItem)formatter.Deserialize(file);  }  if (item.ExpiryDate  DateTime.Now.ToUniversalTime())  {  log.Info(item.ExpiryDate  *  key);  Remove(key);  return null;  }  return item.Item;  }  public override void Set(string key, object entry, DateTime utcExpiry)  {  CacheItem item  new CacheItem(entry, utcExpiry);  string path  ConvertKeyToPath(key);  using (FileStream file  File.OpenWrite(path))  {  BinaryFormatter formatter  new BinaryFormatter();  formatter.Serialize(file, item);  }  }  public override void Remove(string key)  {  string path  ConvertKeyToPath(key);  if (File.Exists(path))  File.Delete(path);   }  public string CachePath  {  get;  set;  }  private string ConvertKeyToPath(string key)  {  string file  key.Replace(/, -);  file  .txt;  return Path.Combine(CachePath, file);  }  }  [Serializable]  public class CacheItem  {  public DateTime ExpiryDate;  public object Item;  public CacheItem(object entry, DateTime utcExpiry)  {  Item  entry;  ExpiryDate  utcExpiry;  }  } 有两个地方需要特别说明 在Add方法中有一个条件判断必须做出这样的处理否则缓存机制将会缓存第一次的结果过了有效期后缓存讲失效并不再重建 在示例程序中我们简单的将缓存放到了Cache目录下在实际的项目实践中考虑到缓存的页面将是成千上万的所以我们必须要做目录分级否则寻找并读取缓存文件将会成为效率瓶颈这会耗尽CPU。 3配置文件 我们需要在Web.config中配置缓存处理程序是自定义的FileCacheProvider即在 system.web下添加节点 caching  outputCache defaultProviderFileCache  providers  add nameFileCache typeMvcApplication2.Common.FileCacheProvider cachePath~/Cache /  /providers  /outputCache   /caching 4缓存的使用 我们假设在MVC的控制中使用如果要在ASP.NET页面中使用则在页面中包含%OutputCache VaryByParamnone Duration10 %可以看到Index是未进行输出缓存的而Index2进行了输出缓存缓存时间为10秒。 public class HomeController : Controller  {  private static readonly ILog log  LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);  static string s_conn  Data Source192.168.0.77;Initial Catalogluminjidb;User Idsa;Passwordsa;;  public ActionResult Index()  {  using (DataSet ds  Common.SqlHelper.ExecuteDataset(s_conn, CommandType.Text, select top 1* from NameTb a, DepTb b where a.DepID  b.ID ORDER BY NEWID()))  {  ViewBag.Message  ds.Tables[0].Rows[0][name].ToString();  }  return View();  }  [OutputCache(Duration  10, VaryByParam  none)]  public ActionResult Index2()  {  using (DataSet ds  Common.SqlHelper.ExecuteDataset(s_conn, CommandType.Text, select top 1* from NameTb a, DepTb b where a.DepID  b.ID ORDER BY NEWID()))  {  ViewBag.Message  ds.Tables[0].Rows[0][name].ToString();  }  return View();  }  } 5查看下效果 上面的代码在访问了Index2后将会在Cache文件夹下产生缓存文件如下 现在我们开始评价下有输出缓存和无输出缓存的性能对比模拟100个用户并发1000次请求如下 可以看到有输出缓存后吞吐率明显提高了10倍。 6代码下载 FileCacheProvider的原始代码来自于网络我修改了其中的BUG全部代码下载如下MvcApplication20110907.rar 职业指导 在使用某一技能三个月后你还不是专家即便使用时间是三年你还不是。马尔科姆·格莱德威尔在《异类》一书中指出成为一名真正的专家需要10000小时。10000小时如果一天用10小时每天都学习则大概需要3年时间。如果一天5小时一年学习200天则大概需要10年时间。10年 原文http://www.cnblogs.com/luminji/archive/2011/09/08/2169955.html
http://www.pierceye.com/news/649692/

相关文章:

  • 电商网站平台有哪些做自己的第一个网站
  • 源码资源下载站百度指数 多少流量 网站名
  • 合肥比较好的网站建设公司青阳网站建设
  • 上海地产网站建设甘肃建设厅网站二级建造师报名时间
  • 扬州网站建设推广泊头网站建设甘肃
  • 什么行业要做网站建设推广这些水墨网站设计欣赏
  • 渠道网站wap百度
  • 在网站上如何做天气预报栏wordpress 分类列表
  • 做网站需要投资多少钱做网站的销售团队
  • 苏州哪个公司做门户网站seo优化方案报价
  • 电力建设官方网站做网站送优化
  • 门户网站建设模式包括网站群和中企动力企业邮箱登陆首页
  • 做调查网站的问卷哪个给的钱高wordpress邮箱注册功能
  • 上海php网站开发基于php网站建设
  • 大丰专业做网站做旅游网站当地人服务赚钱吗
  • 长沙网站制作公司推荐seo关键词排名优化
  • 内蒙古住房与城乡建设部网站广州十大软件公司排名
  • 营销型网站 易网拓德阳做网站
  • 网站建设seo虾哥网络购物网站技术实施方案
  • 门户网站框架下载陕西省建设工会网站
  • 网站有信心做的更好做外贸到什么网站上发布比较好
  • wex5做网站wordpress页面的设置
  • 绍兴市建设银行网站网站建设的基本术语
  • 建筑企业网站模板免费下载seo 网站换程序
  • wordpress怎么做排名seo怎么样
  • 电商网站开发平台哪家好百度运营怎么做
  • 门户网站 源码网站建设推广公司范围
  • 网站字体大小wordpress用户登录页面
  • 影院禁止18岁以下观众入内宿迁新站seo
  • 龙岗网站设计机构网站开发开始阶段的主要任务包括( )。