对于具有动态头的大部分静态页面,什么是最好的Rails缓存选项 [英] What is the best Rails caching option for largely static pages with a dynamic header

查看:82
本文介绍了对于具有动态头的大部分静态页面,什么是最好的Rails缓存选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组基本上是静态的页面,除了它们的布局包含一个更动态的页眉之外,我很乐意页面缓存相对较长的时间。

I have a set of largely static pages which I'd be happy to page cache for relatively long periods apart from the fact that their layout includes a much more dynamic header.

到目前为止,最有希望的想法似乎是在没有布局的情况下使用动作缓存: -

The most promising idea so far seems to be using action caching without layout :-

class SomethingController < ApplicationController

  caches_action :index, :layout => false

end

然后至少将页面的主要内容缓存。这是否合理?

Then at least the main content of the page is cached. Does that make sense?

或者我会做更好的事情,例如片段缓存,服务器端包含等...?

Or would I be better off doing something else, e.g. fragment caching, server-side include, etc...?

推荐答案

我所做的是使用页面缓存,然后使一个AJAX调用来获取:

What I have done is use page caching, and then make an AJAX call to fetch either:


  1. 整个标题。

  2. 标题的特定部分是动态的。

另外,如果您只是想要包含用户名,则存在更好的方法。只需将它们的名称存储在cookie中,然后使用javascript将其显示在标题中。没有cookie,显示一个链接去登录或注册。

Also, if you are just looking to include the users name, a better way exists. Simply store their name in a cookie and then use javascript to display it in the header. With no cookie, show a link to go login or register.

这篇关于对于具有动态头的大部分静态页面,什么是最好的Rails缓存选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆