在Heroku上缓存named_scope? [英] Cached named_scope on Heroku?

查看:104
本文介绍了在Heroku上缓存named_scope?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  scope:current_budget,其中(:budget_review => Appconfig.budget_status)

方法budget_status本身被定义为

  def self.budget_status 
Appconfig.find_by_name('reviewed_budget')。value ==1? true:false
end

在本地测试时,如果我更改了reviewed_budget 参数,然后再次调用作用域,一切正常。



但是在Heroku上,即使我改变参数,它总是会给我相同的结果。
我试图在Heroku上显示Appconfig.budget_status的值,当它改变时我改变了设置。



尽管如此,named_scope似乎并没有这是考虑到的。



这里有一些缓存技巧吗?如果是这样的话,我该如何摆脱这种情况?
其他人,有没有人知道什么可能是错的?

谢谢,
p。



为了确保查询不被缓存可以使用以下语法来代替:

 范围:CURRENT_BUDGET,λ-{其中(:budget_review => Appconfig.budget_status)} 

lambda是什么在这种情况下有所作为。


I have a name scope that takes the result of a query as parameter:

scope :current_budget, where(:budget_review => Appconfig.budget_status)

Method budget_status is itself defined as

def self.budget_status
  Appconfig.find_by_name('reviewed_budget').value=="1" ? true : false
end

When testing locally, if I changed the value of the "reviewed_budget" parameter and then call the scope again, everything works fine.

But on Heroku, it will always give me the same result, even if I change the parameter. I tried to display the value of Appconfig.budget_status on Heroku and it changes when I change my setting.

Still, the named_scope doesn't seem to take this into account.

Is there some caching trick here? if so how do I get rid of this for this specific situation? Else, does anyone have an idea of what could be wrong?

thanks, p.

解决方案

When you test locally, I assume you run a development environment which will reload all your code every time it is called and will because of that avoid this problem. In production (Heroku) however it will cache, not the result but the query, of the scope if used like you do currently.

To make sure the query is not cached you can use the following syntax instead:

scope :current_budget, lambda { where(:budget_review => Appconfig.budget_status) }

lambda is what makes a difference in this case.

这篇关于在Heroku上缓存named_scope?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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