gpt4 book ai didi

ruby-on-rails - 检测 Action 是否缓存在 Rails 中的可能方法?

转载 作者:行者123 更新时间:2023-12-02 02:23:12 24 4
gpt4 key购买 nike

使用 Rails 3,是否可以检测布局内部或 before_filter 以查看是否要缓存操作以及该操作是否命中缓存?

caches_index :something, :layout => false

例如(在 application.html.erb 中)

<%= yield %>
<% @is_cached == ... %>

是否可以在对项目的 yield 调用之前和/或之后执行此操作?

最佳答案

我正在以这种方式使用片段缓存:

  #helper
def cache_unless(condition, name = {}, &block)
unless condition
cache(name, &block)
else
yield
end
end


#view
<% cache_unless has_permission?, :action => :index, :folder => @folder, :user_id => @user.id do %>
...
<% end %>

关于ruby-on-rails - 检测 Action 是否缓存在 Rails 中的可能方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7143942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com