2013-02-27 44 views
1

我想調試/打印值的代碼塊調試內部Rails.cache.fetch

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

end 

與Rails.logger.ap,看跌期權,調試器嘗試內。什麼都沒有解決。我假設它只是由於緩存提取?

請給我一些解決方案。提前致謝。

+2

刪除緩存內容,該塊將被調用 – apneadiving 2013-02-27 07:47:53

回答

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)

+0

非常感謝apneadiving和jvnill。它運作良好(y)。 – 2013-02-27 09:23:54