【问题标题】:Rails fragment cache not working properly [duplicate]Rails片段缓存无法正常工作[重复]
【发布时间】:2014-08-09 05:34:27
【问题描述】:

我看到了这段代码

<% 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 %>

我在另一个动作中有过期代码

  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

结束

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

缺少什么?

【问题讨论】:

  • 你在哪里更新@swimming_students
  • @spickermann 我必须更新@swimming_students吗? expire_fragment("students_cache") 不应该过期缓存吗?

标签: ruby-on-rails ruby caching ruby-on-rails-4


【解决方案1】:

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

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

更多详情请见this Stackoverflow question

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    相关资源
    最近更新 更多