Duration of the action cache with the user_path cache

I am having a problem with expiring the action cache in my application.

Here is my controller:

class ToplistsController < ApplicationController caches_action :songs, cache_path: :custom_cache_path.to_proc def custom_cache_path "#{params[:when]}-#{params[:what]}-#{params[:controller]}-#{params[:action]}" end def songs # ... end end 

I somehow need to be able to reset the cache path, but I can’t figure out how to do this.

I have already tried using this technique without success. It looks like Dalli, which is my caching mechanism, does not support regex.

I get this error when trying to use this code:

expire_fragment(/songs/)

ActiveSupport::Cache::DalliStore does not support delete_matched

I tried to use this line of code for debugging but it was ignored.

 before_filter only: [:songs] expire_fragment(custom_cache_path) end 

I am using Rails 3.1.0.rc6, Dalli 1.0.5 and Ruby 1.9.2.

+7
source share
2 answers

The before_filter block before_filter ignored in the action cache.
The solution is to use a fragment cache.

 # Controller class ToplistsController < ApplicationController helper_method :custom_cache_path before_filter only: [:songs] if params[:reset_cache] expire_fragment(custom_cache_path) end end def custom_cache_path "#{params[:when]}-#{params[:what]}-#{params[:controller]}-#{params[:action]}" end def songs # ... end end # View <%= cache custom_cache_path do %> Content that should be cached <% end %> 
0
source

You can also check the solution here . With his approach, you can complete actions with additional parameters.

0
source

All Articles