Rails片段缓存无法正常工作[重复]

时间:2020-12-30 03:51:31

This question already has an answer here:

这个问题在这里已有答案:

I have this piece of code in view

我有这段代码

<% cache("students_cache") do %>
  <% @swimming_students.each do |swimming_student| %>
    <tr class="gradeX">
      <td><%= link_to " #{swimming_student.full_name}", swimming_student %></td>
      <td><%= swimming_student.homephone %></td>          
    </tr>
  <% end %>
<% end %>

And I have the expire code in anther action

而且我在其他行动中有过期代码

  def create
     expire_fragment("students_cache")
    @swimming_student = Swimming::Student.new(params[:swimming_student])

    respond_to do |format|
      if @swimming_student.save
        format.html { redirect_to @swimming_student, notice: 'Student was successfully created.' }
        format.json { render json: @swimming_student, status: :created, location: @swimming_student }
      else
        format.html { render action: "new" }
        format.json { render json: @swimming_student.errors, status: :unprocessable_entity }
      end
    end

end

结束

But after I created a new student the cache was not updated.

但在我创建一个新学生后,缓存没有更新。

Something is missing?

缺了点什么?

1 个解决方案

#1


3  

When using fragment caching with string keys, you should turn off cache digests:

使用带字符串键的片段缓存时,应关闭缓存摘要:

<% cache("students_cache", skip_digest: true) do %>

See this * question for more details.

有关更多详细信息,请参阅此*问题。

#1


3  

When using fragment caching with string keys, you should turn off cache digests:

使用带字符串键的片段缓存时,应关闭缓存摘要:

<% cache("students_cache", skip_digest: true) do %>

See this * question for more details.

有关更多详细信息,请参阅此*问题。