簡體   English   中英

在Rails.cache.fetch內部進行調試

[英]Debugging inside Rails.cache.fetch

我想調試/打印代碼塊中的值

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

end

與Rails.logger.ap一起嘗試,放置調試器。 什么都沒解決。 我假設這僅僅是由於緩存獲取?

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

只是為了解釋呼吸暫停的評論。

由於您正在使用緩存,因此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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM