Answer the question
In order to leave comments, you need to log in
Is it possible to access the current object in an if statement?
last_update = Page.order(updated_at: :desc).first.updated_at.to_i
if Rails.cache.fetch("#{last_update}/all_pages_cached").present?
Rails.cache.fetch("#{last_update}/all_pages_cached")
else
Rails.cache.fetch("#{last_update}/all_pages_cached") do
hash # некий хэш
end
end
last_update = Page.order(updated_at: :desc).first.updated_at.to_i
if Rails.cache.fetch("#{last_update}/all_pages_cached").present?
current_object # вот так
else
Rails.cache.fetch("#{last_update}/all_pages_cached") do
hash # некий хэш
end
end
Answer the question
In order to leave comments, you need to log in
If there is no such data in the cache (a cache miss), then nil will be returned. However, if a block has been passed, that block will be passed the key and executed in the event of a cache miss. The return value of the block will be written to the cache under the given cache key, and that return value will be returned.
Rails.cache.fetch("#{last_update}/all_pages_cached") do
hash
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question