【问题标题】:cache_unless still computes the cache key although the condition is true尽管条件为真,cache_unless 仍然计算缓存键
【发布时间】:2016-12-22 02:06:27
【问题描述】:

我有一个简单的片段缓存:

-cache_unless user_signed_in?, ['show', @question, @question.user.username, @question.user.score, @question.user.avatar_url] do 

当我登录时页面没有被缓存,这是我想要的,但是,缓存键仍在计算中,我可以在我的日志中看到 ActiveRecord 查询。

如果条件为真,我希望缓存不会计算新的缓存键。

【问题讨论】:

    标签: ruby-on-rails activerecord russian-doll-caching


    【解决方案1】:

    我不得不使用简单的 if else 逻辑:

    if user_signed_in? 
      #render uncached resources
    else
      #cache 
    end
    

    【讨论】:

      猜你喜欢
      • 2015-04-18
      • 2020-09-29
      • 1970-01-01
      • 2018-09-16
      • 1970-01-01
      • 2018-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多