• 如何设置页面缓存或不用页面缓存


    一、设置页面缓存

    1、直接在页面上用<%@ OutputCache Duration="10" VaryByParam="None" %>声明来缓存页面

    2、使用服务端方法:

    //将Cache-Control标头设置为HttpCacheAbility值

    Response.Cache.SetCacheability(HttpCacheability.Public);

    //将页面的绝对过期时间

    Response.Cache.SetExpires(DateTime.Now.AddSeconds(20));

    3、对用户的请求以304响应 

    DateTime dt;

    //从http请求头获取If-Modified-Since值,判断该值与当前的差值是否超出要缓存的时间,如果超出则重新加载页面,否则以304响应
    DateTime.TryParse(Request.Headers["If-Modified-Since"], out dt);
    if ((DateTime.Now - dt).TotalSeconds < 30.0) {
    Response.StatusCode = 304;
    Response.End();
    return;
    }

    //第一次加载的时候要设置Last-Modified为当前时间,下次再次请求当前页的时候会将该值以If-Modified-Since发送到服务端
    Response.Cache.SetLastModified(DateTime.Now);

    二、不用页面缓存

    1、如果是静态的css或js文件则可以在文件后加上参数?t=234

    2、服务端则可以使用:

      //设置http标头的Cache-Control:no-store

      Response.Cache.SetNoStore();

  • 相关阅读:
    js-link下载文件
    sql-优化建议
    Studio-环境变量设置
    Studio
    Docker下安装ElasticSearch和Kibana
    sklearn 中的 r2_score
    R语言将所有列数据正交化/缩放
    R语言 random forests out-of-bag prediction
    R语言 coalesce 函数
    R语言 case_when 函数
  • 原文地址:https://www.cnblogs.com/jiangjun0817/p/3695252.html
Copyright © 2020-2023  润新知