0

在 redmine 1.2/rails 2.3.11 上,我正在将存储库降价文件呈现为 html(就像redmine_markdown_extra_viewer所做的那样),现在我正在尝试缓存结果,该结果应该在每次提交时更新。

所以我有一个获取 repo 更改的 git 钩子,我希望它也清除相应的缓存条目。

缓存生成(在 RepositoriesController::entry 覆盖中):

cache_key =['repositories_md', @project.id.to_s, @path.to_s].join('/')
puts cache_key
@content = cache_store.fetch cache_key do
   Kramdown::Document.new(@repository.cat(@path, @rev)).to_html
end
render :action => "entry_markdown"

应该清除缓存但没有效果的钩子:

# This is ok
ruby script/runner "Repository.fetch_changesets"

# This not
ruby script/runner "Rails.cache.delete_matched(/repositories_md\/.*/)"

所以它不起作用,我什至不知道我是否采取了正确的方向来实现它。非常感谢任何输入!

4

2 回答 2

4

您使用的是哪个缓存后端?

如果它是 memcached 或除 或 之外的任何东西FileStore则不支持MemoryStoredelete_matched方法。

您最好让它们过期并在更新时替换它们的缓存内容。

于 2011-12-23T11:41:13.660 回答
0

问题是当使用正则表达式作为片段名称时,请尝试使用字符串作为片段名称。也许会变得冗长。我对 Dalli(使用 Memcached)也有类似的问题,这就是原因。

于 2016-05-13T13:18:56.450 回答