方法:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace PaiXie.Pos.Admin {
/// <summary>
/// 缓存页面
/// </summary>
public class CacheFilterAttribute : ActionFilterAttribute {
/// <summary>
/// Gets or sets the cache duration in seconds. The default is 10 seconds.
/// </summary>
/// <value>The cache duration in seconds.</value>
public int Duration {
get;
set;
}
public CacheFilterAttribute() {
Duration = ;
}
public override void OnActionExecuted(ActionExecutedContext filterContext) {
if (Duration <= ) return;
HttpCachePolicyBase cache = filterContext.HttpContext.Response.Cache;
TimeSpan cacheDuration = TimeSpan.FromSeconds(Duration);
cache.SetCacheability(HttpCacheability.Public);
cache.SetExpires(DateTime.Now.Add(cacheDuration));
cache.SetMaxAge(cacheDuration);
cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
}
}
}

调用:

      [CacheFilter]
public ActionResult Index() {
}

mvc 缓存页面 减轻服务器压力的更多相关文章

  1. centos6.6安装redis服务安装redis服务,对于discuz来说可以作为缓存使用,减轻服务器压力

    获取redis源码包 #wget http://download.redis.io/releases/redis-stable.tar.gz 解压缩 #tar xf  redis-stable.tar ...

  2. juqery 实现 防止当前页面重复点击,以减轻服务器压力

    <script> //防止当前页面重复点击,以减轻服务器压力 $(document).ready(function () { var current_url = location.path ...

  3. 使用 ETag 和 Last-Modified 报头减轻服务器压力(转)

    介绍你的网站在并发访问很大并且无法承受压力的情况下,你会选择如何优化?很多人首先会想从服务器缓存方面着手 对程序进行优化,许多不同的服务器缓存方式都有他们自己的特点,像我曾经参与的一些项目中,根据缓存 ...

  4. Springzz中使用监听器,用于容器一启动就加载准备数据(application范围内的数据,用于减轻服务器压力,不用每次都去查数据)

    java代码: public class InitListener implements ServletContextListener { public void contextInitialized ...

  5. ASP.NET MVC 缓存页面(方法)

  6. php后台操作以及一些减缓服务器压力的问题

    上次提到一个微信投票系统,做了一个微信重定向解决了,一个授权复用的问题,昨天投票系统正式投入使用:测试的时候没有问题,上线后出现了一点小问题, 一:php页面参数接受和php中 switch 那个先执 ...

  7. 减少服务器压力php生成静态xml文件

    一.引 言 在速度上,静态页面要比动态页面的比方php快很多,这是毫无疑问的,但是由于静态页面的灵活性较差,如果不借助数据库或其他的设备保存相关信息的话,整体的管理上比较繁琐,比方修改编辑.比方阅读权 ...

  8. MVC 全站开启缓存,缓解服务器的请求压力

    protected void Application_BeginRequest() { //获取当前请求的url string url = HttpContext.Current.Request.Pa ...

  9. 使用Donut Caching和Donut Hole Caching在ASP.NET MVC应用中缓存页面

    Donut Caching是缓存除了部分内容以外的整个页面的最好的方式,在它出现之前,我们使用"输出缓存"来缓存整个页面. 何时使用Donut Caching 假设你有一个应用程序 ...

随机推荐

  1. Oracle数据库imp

    创建表空间 create tablespace ICITY datafile 'D:\Oracle\oradata\orcl\ICITY.DBF' size 400M autoextend on ne ...

  2. redis 五种数据结构详解(string,list,set,zset,hash),各种问题综合

    redis 五种数据结构详解(string,list,set,zset,hash) https://www.cnblogs.com/sdgf/p/6244937.html redis 与 spring ...

  3. 微信小程序 - scroll-into-view(提示)

    scroll-view的参数scroll-into-view适用于索引以及回到顶部 .详情见官方文档scroll-view: 点击下载:scroll-into-view示例

  4. loadrunner -27492超时

  5. ReactNative踩坑日志——使用async/await语法解决网络请求的异步导致的指令执行顺序错乱问题

    转载请注明原文地址: ReactNative的fetch是天然的异步请求,因此,如果你在一个代码块中使用了fetch,那么在执行的时候程序不会等待网络响应结束才执行下一条代码,而是会直接按顺序执行完整 ...

  6. SpringMVC学习笔记六:使用 hibernate-validator注解式数据校验

    对客户端传过来的参数,在使用前一般需要进行校验. SpringMVC框架内置了Validator验证接口,但是实现起来太麻烦.我们一般使用 hibernate-validator进行数据校验. 1:j ...

  7. Spring学习笔记四:SpringAOP的使用

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6776247.html  一:AOP基础概念 (1)通知(增强)Advice 通知,其实就是我们从众多类中提取出 ...

  8. 〖Linux〗将Jar文件打包成Linux可执行文件

    因为不想敲写 java -jar jarfile,而是想直接敲写  ./jarfile 就能够跑起程序 #!/bin/bash - #================================= ...

  9. wordpress 开源博客系统部署

     1.开发工具 server apache    下载地址:http://www.apache.org   http://httpd.apache.org/download.cgi 数据库 mys ...

  10. CPLSetErrorHandlerEx函数Bug

    CPLSetErrorHandlerEx(gdal/gdal/port/cpl_error.cpp,当前github中代码)当前函数实现如下 CPLErrorHandler CPL_STDCALL C ...