Answer the question
In order to leave comments, you need to log in
Is caching done correctly?
Hello!
There is a partial menu.
I want to cache this fragment, it seems to work, but when updating the entry in the menu, the partial remains the same, the cache is not reset, I don’t understand what’s wrong.
_menu.slim
- menu = render_menu(code)
ul class="nav navbar-nav navbar-right"
= cache ['menu', Menu.latest]
- menu.each do |item|
= cache item do
li
= (item.page.template.name == "index") ? link_to(item.page.title, "/") : link_to(item.page.title, item.page.slug)
def self.latest
MenuTranslation.order(:updated_at).last
end
def render_menu(code)
menu = Menu.find_by :code => code
menu.children
end
Answer the question
In order to leave comments, you need to log in
The cache function can take either a ready-made key for storage, or, as in your case, a model instance. In this case, the key will be built from id and updated_at, so updated_at must be in all models.
It is also called before the first cache in your code
, in this case there is no point in the first cache call. The
easiest way is to look at the console logs;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question