1-缓存

1. 页面缓存+URL缓存+对象缓存

  1.1 页面缓存

    区缓存

    手动渲染模板

    结果输出

  代码片段

    @RequestMapping(value="/to_list", produces="text/html")
    @ResponseBody
    public String list(HttpServletRequest request, HttpServletResponse response, Model model,MiaoshaUser user) {
        model.addAttribute("user", user);
        //取缓存
        String html = redisService.get(GoodsKey.getGoodsList, "", String.class);
        if(!StringUtils.isEmpty(html)) {
            return html;
        }
        List<GoodsVo> goodsList = goodsService.listGoodsVo();
        model.addAttribute("goodsList", goodsList);
//         return "goods_list";
        SpringWebContext ctx = new SpringWebContext(request,response,
                request.getServletContext(),request.getLocale(), model.asMap(), applicationContext );
        //手动渲染
        html = thymeleafViewResolver.getTemplateEngine().process("goods_list", ctx);
        if(!StringUtils.isEmpty(html)) {
            redisService.set(GoodsKey.getGoodsList, "", html);
        }
        return html;
    }

  1.2 对象缓存

    public MiaoshaUser getById(long id) {
        //取缓存
        MiaoshaUser user = redisService.get(MiaoshaUserKey.getById, ""+id, MiaoshaUser.class);
        if(user != null) {
            return user;
        }
        //取数据库
        user = miaoshaUserDao.getById(id);
        if(user != null) {
            redisService.set(MiaoshaUserKey.getById, ""+id, user);
        }
        return user;
}

2.页面静态化,前后端分离

  2.1 常用技术AngularJS,Vue.js

  2.2 优点:利用浏览器的缓存

sprint 配置

spring.resources.add-mappings=true
spring.resources.cache-period= 3600
spring.resources.chain.cache=true 
spring.resources.chain.enabled=true
spring.resources.chain.gzipped=true
spring.resources.chain.html-application-cache=true
spring.resources.static-locations=classpath:/static/

3.静态资源优化

  3.1 JS/CSS 压缩,减少流量

  3.2 多个JS/CSS 组合,减少链接数(Tengine)

    组合多个CSS,JavaScript文件的访问请求变成一个请求

    自动去除注释和空格,从而减少页面的体积(注入Webpack工具)

4. CDN 优化(Content Delivery Network)

  4.1 

猜你喜欢

转载自www.cnblogs.com/likevin/p/9195808.html