条件页面缓存[解决方案:条件片段缓存] [英] Conditional Page Caching [Solution: Conditional Fragment Caching]

查看:64
本文介绍了条件页面缓存[解决方案:条件片段缓存]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的控制器 home_controller.rb 的操作为 index

Suppose that I have controller home_controller.rb with action index.

我想缓存索引页,所以我在做:

I want to cache index page so I'm doing:

caches_page :index

,但希望它仅对未登录的用户进行缓存。如果我将条件作为:

but want it to cache only for users that are not signed in. If I'll make conditional like:

caches_page :index, :if => :user_not_signed_in?

页面将被缓存,而第一个未登录的用户来了。现在,每个登录用户也可以看到未登录的内容。有没有办法在不更改URL的情况下分隔此操作?

Page will be cached while first not logged in user comes. Now every logged in user also see not-logged in content. Is there a way to separate this action without changing url?

推荐答案

cache_if cache_unless 似乎是现在执行此操作的正确方法:

cache_if and cache_unless seems to be the correct way to do this now:

cache_if(condition, name = {}, options = nil, &block)
cache_unless(condition, name = {}, options = nil, &block)

您的代码:

<%cache_unless @ user.changed?,[@用户,表单]做%>

这篇关于条件页面缓存[解决方案:条件片段缓存]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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