我一直在尝试使用 rails 的缓存功能,但我无法使某些缓存片段过期,尽管它们似乎已过期。使用rails教程站点中指出的“俄罗斯娃娃缓存”,我正在使用此配置
<% cache "all_available_releases" do %>
<% @releases.each do |release| %>
<% cache(release) do %>
<html code with>
<%ruby code @release.name blah blah blah%>
<%end%>
<%end%>
<%end%>
我使 release_controller.rb 控制器中的外部缓存过期,我使用 expire_fragment("all_available_releases") 使片段过期。我在控制器的每个更新、删除或添加条目的方法中都使用它。
这是 WEBrick 的日志,虽然过期片段被注册,但 5 行后过期片段被读取并使用,而它不应该。这个例子是在销毁调用之后。
Processing by ReleasesController#destroy as HTML
Parameters: {"authenticity_token"=>"***/***/********************+********=", "id"=>"2"}
Release Load (0.1ms) SELECT "releases".* FROM "releases" WHERE "releases"."id" = ? LIMIT 1 [["id", "2"]]
(0.1ms) begin transaction
SQL (2.0ms) DELETE FROM "releases" WHERE "releases"."id" = ? [["id", 2]]
(148.0ms) commit transaction
Expire fragment views/all_available_releases (0.1ms)
Redirected to http://127.0.0.1:3000/releases
Completed 302 Found in 180ms (ActiveRecord: 150.2ms)
Started GET "/releases" for 127.0.0.1 at 2013-07-03 13:09:51 +0300
Processing by ReleasesController#index as HTML
Read fragment views/all_available_releases/41cb0a928326986f35f41c52bb3d8352 (0.1ms)
Rendered releases/index.html.erb within layouts/application (0.6ms)
Completed 200 OK in 5ms (Views: 4.0ms | ActiveRecord: 0.0ms)
我什至尝试使用Rails.cache.delete("all_available_releases")
它也没有工作。
如果我从我的 html.erb 中删除<%cache "all_available_releases"%>
(和一个<%end%>
),则缓存工作正常,并且会在任何时候过期。