ASP.NET的缓冲处理

Caching Overview
Caching is a technique that is widely used in computing to increase performance by keeping frequently accessed or expensive data in memory. In the context of a Web application, caching is used to hold onto pages or data across HTTP requests and reuse them without the expense of recreating them.

ASP.NET has two kinds of caching that can be utilized by Web applications.

  • Caching the dynamic response generated by a request is known as Output Caching.
  • The caching of arbitrary objects programmatically is known as Data Caching. To support this, ASP.NET provides a full featured Cache engine that allows programmers to easily hold onto data across requests.

Output caching is useful when the contents of an entire page can be cached. On a heavily accessed site, caching frequently accessed pages for even a minute at a time can result in substantial throughput gains. While a page is cached by the output cache, subsequent requests for that page are served from the output page without executing the code that created it.

Sometimes it's not practical to cache an entire page--perhaps portions of the page must be created or customized for each request. In this case, it's oftentimes worthwhile to identify objects or data that are expensive to construct that are eligible for caching. Once these items are identified, they can be created once and then cached for some period of time.

Choosing the time to cache an item can make for an interesting decision. For some items, the data might be refreshed at regular intervals or the data is valid for a certain amount of time. In that case, the cache item can be given an expiration policy that will cause them to be removed from the cache when they're expired. Code that accesses the cache item simply checks for the absence of the item, and recreates it if necessary.

The ASP.NET cache supports file and cache key dependencies, allowing developers to make a cache item dependent on an external file or another cache item. This technique can be used to invalidate items when their underlying data source changes.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
ASP.NET MVC 一般处理程序(General Handler),也称为 ashx 文件,是一种在 ASP.NET MVC 中用于处理特定请求的一种方式。 ASP.NET MVC 一般处理程序继承自 IHttpHandler 接口,它主要用于处理静态文件或非标准的请求。与控制器不同,一般处理程序不需要路由或视图,它直接接受请求并返回处理结果。 一般处理程序在项目中以 .ashx 的文件形式存在,可以在其中实现一些自定义的处理逻辑。可以通过在 Global.asax 文件中注册路由来映射一般处理程序的请求。 与控制器相比,一般处理程序更轻量级,更适合处理一些简单的请求,如文件下载、图片验证码生成等。它使用起来更加灵活,并且性能也更好。 使用一般处理程序的步骤如下: 1. 在项目中创建一个 .ashx 文件。 2. 实现一般处理程序的逻辑,可以通过实现 ProcessRequest 方法来处理请求,同时还可以通过实现 IRequiresSessionState 接口来访问会话状态。 3. 在 Global.asax 文件中注册一般处理程序的路由,指定请求的 URL 模式和对应的一般处理程序类名。 4. 在浏览器中访问对应的 URL,即可触发一般处理程序的逻辑,并返回处理结果。 总之,ASP.NET MVC 一般处理程序是一种用于处理特定请求的方式,它比控制器更轻量级、更灵活,适合处理一些简单的请求。我们可以通过创建一般处理程序文件,实现自定义逻辑,并在 Global.asax 文件中注册路由来使用一般处理程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孟子E章

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值