Rails-etags与页面缓存(文件缓存) [英] Rails - etags vs. page caching (file cache)

查看:104
本文介绍了Rails-etags与页面缓存(文件缓存)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

何时使用etags / stale有什么优势?/ fresh_when?而不是页面缓存(在文件缓存上)?

What would be some advantages of using etags/stale?/fresh_when? instead of page caching (on a file cache)?

Apache自动处理静态文件的etag,但是即使不是,页面缓存仍然会更好,因为

Apache automatically handles etags for static files, but even if it didn't, page caching would still be better since the Rails app doesn't even get called.

因此,在什么情况下我会使用Rails提供的方法(陈旧?/何时?)?

So, in what instances would I use the methods provided by Rails (stale?/fresh_when?)?

推荐答案

它们真的是免费的。 Etags / fresh_when等可帮助您与下游缓存(例如您自己的Varnish / Squid实例或Rack :: Cache或浏览器缓存或ISP代理服务器…)一起玩耍

They are really complimentary. Etags/fresh_when etc. help you play nice with downstream caches (like your own Varnish/Squid instances or Rack::Cache or the Browser cache or ISP Proxy Servers…)

页面缓存可避免您完全陷入困境,因为Apache /您的网络服务器为文件提供服务,因此无需进行数据库查找。但是,您必须处理缓存过期以保持缓存新鲜。

Page caching saves you from hitting your rails stack entirely because Apache/your webserver serve the file, so no DB lookups are done. But you have to deal with cache expiration to keep the cache fresh.

使用etags /有条件的get,由于您仍需要获取页面上使用的所有记录:

Using etags/conditional get, you don't save much processing time since you still need to to get all the records used on the page:

def show
  @article = Article.find(params[:id])
  @feature = Feature.current
  fresh_when :etag => [@article, @feature] 
end

页面,它可以节省一些渲染时间和向下发送页面所需的带宽。

in the case that the user has a current page, it saves you some rendering time and the bandwidth required to send down the page.

这篇关于Rails-etags与页面缓存(文件缓存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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