- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我一直在尝试使用 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 Controller 中使外部缓存过期,我在其中使用 expire_fragment("all_available_releases") 使片段过期。我在更新、删除或添加条目的 Controller 的每个方法中都使用它。
这是 WEBrick 的日志,尽管过期片段已在其中注册,但 5 行后过期片段被读取并使用,而这是不应该的。这个例子是在 destroy 调用之后。
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")
而且它也没有用。
如果我删除 <%cache "all_available_releases"%>
(和一个 <%end%>
)从我的 html.erb 缓存工作正常,并在它应该过期的时候过期。
最佳答案
我认为问题是当您在 View 中缓存片段时,缓存摘要被添加到缓存键 (views/all_available_releases/41cb0a928326986f35f41c52bb3d8352),但 expire_fragment 没有使用摘要( View /all_available_releases)。
如果您将 skip_digest: true
添加到 View 中的缓存调用,它应该会阻止使用摘要。
<% cache "all_available_releases", skip_digest: true do %>
<% @releases.each do |release| %>
<% cache(release) do %>
<html code with>
<%ruby code @release.name blah blah blah%>
<%end%>
<%end%>
<%end%>
缓存摘要仅用于自动缓存过期。如果您需要手动使缓存键过期,则不能使用缓存摘要。
关于ruby-on-rails - Rails 4.0 expire_fragment/缓存过期不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17445994/
我一直在尝试使用 Rails 的缓存功能,但我无法使某些缓存片段过期,尽管它们似乎已过期。使用 Rails 教程站点中指出的“俄罗斯娃娃缓存”,我正在使用此配置
我几乎什么都试过了,但似乎无法使用来自模型的 expire_fragment?我知道你不应该这样做非 MVC,但肯定有很多方法可以做到。 我在 lib/cache_helper.rb 中用我所有的过期
我一直在将 Rails 2 应用程序升级到 Rails 3.2.13,但在尝试启用缓存时遇到了问题。缓存在 Rails 2 中有效,我使用的是相同版本的 Ruby - 1.8.7。我不确定它是否相关,
我是一名优秀的程序员,十分优秀!