在Rails.cache.fetch中调试

时间:2013-02-27 07:02:16

标签: ruby-on-rails debugging

我想调试/打印代码块中的值

Rails.cache.fetch(some values) do
 #want to get the values from this blocks.

end

尝试使用Rails.logger.ap,puts,debugger。什么都没有成功。我假设它只是由于缓存提取?

请建议我一些解决方案。提前谢谢。

1 个答案:

答案 0 :(得分:1)

只是阐述apneadiving评论的内容。

由于您正在使用缓存,因此Rails只会运行该块一次,直到您删除内容为止。请参阅以下代码中的内容

>> Rails.cache.fetch(:foo) { 'bar' } # writes 'foo' to cache with value 'bar' since this is the first time you run the command
>> Rails.cache.fetch(:foo) { 'bar' } # fetches 'foo' from cache since it's already in the cache so the block is not executed

如果要调试块内部的内容,可以先删除对缓存的调用(始终评估块)或在块之前添加Rails.cache.delete(:foo)