My controller has this:
我的控制器有这个:
caches_action :render_ticker_for_channel, :expires_in => 30.seconds
In my routes file I have this:
在我的路线文件中,我有这个:
match '/render_c_t/:channel_id' => 'render#render_ticker_for_channel', :as => :render_channel_ticker
In the log file I see this:
在日志文件中我看到:
Write fragment views/mcr3.dev/render_c_t/63 (11.6ms)
How do I expire this manually? I need to expire this from a different controller than the render controller, but even within the render controller I can't get it to expire the right thing.
我如何手动过期?我需要从与渲染控制器不同的控制器使其到期,但即使在渲染控制器中,我也无法让它过期正确的事情。
If I do:
如果我做:
expire_action(:controller => 'render', :action => 'render_ticker_for_channel', :id => c.id)
I see:
Expire fragment views/mcr3.dev/render/render_ticker_for_channel/63 (3.2ms)
If I do:
如果我做:
expire_action(:controller => 'render', :action => 'render_c_t', :id => c.id)
I see:
Expire fragment views/mcr3.dev/render/render_c_t/63 (3.2ms)
This:
expire_action("render_c_t/#{c.id}")
produces:
Expire fragment views/render_c_t/63 (3.5ms)
How can I get it to expire the same path that 'caches_action' is producing?!
我怎样才能让它过期'caches_action'产生的路径?!
3 个解决方案
#1
5
Use the regex version of expire_fragment:
使用expire_fragment的正则表达式版本:
expire_fragment %r{render_c_t/#{c.id}/}
#2
0
There should definitely be a more "Rails Way" to do this, but this might work as a back door: Rails.application.routes.url_helpers
will give you access to your helpers and each will return a string that's the path and/or url that would be sent to the browser in a Location header.
应该有更多的“Rails方式”来做到这一点,但这可能作为一个后门:Rails.application.routes.url_helpers将让你访问你的助手,每个将返回一个字符串,它是路径和/或网址将在Location标头中发送到浏览器。
Try Rails.application.routes.url_helpers.render_ticker_for_channel_path(63)
which should return /render_c_t/63
and Rails.application.routes.url_helpers.render_ticker_for_channel(63, :host => 'mcr3.dev')
which should return http://mcr3.dev/render_c_t/63
尝试Rails.application.routes.url_helpers.render_ticker_for_channel_path(63),它应返回/ render_c_t / 63和Rails.application.routes.url_helpers.render_ticker_for_channel(63,:host =>'mcr3.dev'),它们应返回http:// mcr3.dev/render_c_t/63
With some manipulation you could parse apart that second string to get back to the name that Rails is using for the cached action:
通过一些操作,您可以解析第二个字符串以回到Rails用于缓存操作的名称:
def funky_action_cache_name(route, params)
Rails.application.routes.url_helpers.send(route.to_s+'_url', params).gsub(/https?:\/\//,'')
end
# expire_action(funky_action_cache_name(:render_ticker_for_channel, :id => 63))
Not the most beautiful solution, but should work!
不是最美丽的解决方案,但应该工作!
#3
-1
caches_action :render_ticker_for_channel, :if => proc do
!!params['doCache']
end
But for this solution to work we need to pass an extra param either through query string or post body.
但是要使这个解决方案起作用,我们需要通过查询字符串或帖子体来传递额外的参数。
#1
5
Use the regex version of expire_fragment:
使用expire_fragment的正则表达式版本:
expire_fragment %r{render_c_t/#{c.id}/}
#2
0
There should definitely be a more "Rails Way" to do this, but this might work as a back door: Rails.application.routes.url_helpers
will give you access to your helpers and each will return a string that's the path and/or url that would be sent to the browser in a Location header.
应该有更多的“Rails方式”来做到这一点,但这可能作为一个后门:Rails.application.routes.url_helpers将让你访问你的助手,每个将返回一个字符串,它是路径和/或网址将在Location标头中发送到浏览器。
Try Rails.application.routes.url_helpers.render_ticker_for_channel_path(63)
which should return /render_c_t/63
and Rails.application.routes.url_helpers.render_ticker_for_channel(63, :host => 'mcr3.dev')
which should return http://mcr3.dev/render_c_t/63
尝试Rails.application.routes.url_helpers.render_ticker_for_channel_path(63),它应返回/ render_c_t / 63和Rails.application.routes.url_helpers.render_ticker_for_channel(63,:host =>'mcr3.dev'),它们应返回http:// mcr3.dev/render_c_t/63
With some manipulation you could parse apart that second string to get back to the name that Rails is using for the cached action:
通过一些操作,您可以解析第二个字符串以回到Rails用于缓存操作的名称:
def funky_action_cache_name(route, params)
Rails.application.routes.url_helpers.send(route.to_s+'_url', params).gsub(/https?:\/\//,'')
end
# expire_action(funky_action_cache_name(:render_ticker_for_channel, :id => 63))
Not the most beautiful solution, but should work!
不是最美丽的解决方案,但应该工作!
#3
-1
caches_action :render_ticker_for_channel, :if => proc do
!!params['doCache']
end
But for this solution to work we need to pass an extra param either through query string or post body.
但是要使这个解决方案起作用,我们需要通过查询字符串或帖子体来传递额外的参数。