dav*_*idb 8 caching ruby-on-rails ruby-on-rails-3.2
我的网站上有很多缓存片段,因为我使用片段action_suffix缓存在我的应用程序模板中使用缓存.我使用这个用于导航,例如,...像这样:
<% cache(:action => params[:action], :action_suffix => "navigation_#{request.path}") %>
<%= render 'navigation_entries/navigation' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但现在我有一个小问题到期缓存碎片.我需要的是缓存片段的所有密钥列表.我不仅仅看了一下文档,但我找不到任何东西.
有没有办法列出所有片段密钥?
你可以传递Regexp给expire_fragment:
expire_fragment(%r{navigation_})
Run Code Online (Sandbox Code Playgroud)
根据文件
只有可以迭代所有键的缓存(与memcached不同)才支持Regexp到期.
我无法在rails cache上找到列出所有键的方法,但是如果您使用的是默认文件缓存,则可以通过查看文件系统来列出它们.当在unix/linux上的默认rails目录中时,您可以使用类似这样的内容来查看所有缓存文件(以密钥url编码后命名):
find ./tmp/cache -type f
Run Code Online (Sandbox Code Playgroud)
或者这也是取消编码和剥离dirs:
find ./tmp/cache -type f | xargs ruby -e 'require "cgi";puts CGI::unescape(ARGV.sort.join("\n")).gsub(/.*tmp\/cache\/\w*\/\w*\//,"")'
Run Code Online (Sandbox Code Playgroud)
使用正则表达式删除将允许您删除大多数键,但是对于调试,如果您使用复杂的键,有时可以看到您正在存储的实际键.
| 归档时间: |
|
| 查看次数: |
2708 次 |
| 最近记录: |