Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

expire_action can expire by the custom path directly #3267

Closed
wants to merge 1 commit into from

3 participants

@sishen

expire_action can expire the custom path directly instead of passing :controller/:action for url generator.

For example,

caches_action :feed, :cache_path => proc do
    if params[:user_id]
      user_list_url(params[:user_id, params[:id])
    else
      list_url(params[:id])
    end
 end

So we can use expire_action(list_url(params[:id])) to expire the cache.

@isaacsanders

@sishen Is this still an issue?

@sishen

@isaacsanders I think it should already be fixed by a pull request months later than mine. Thanks.

@rafaelfranca

True. This code is already on master. Thanks.

@isaacsanders thanks for helping. If you see any issues that can be closed please ping me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 9, 2011
  1. @sishen

    expire_action can expire the custom path directly instead of passing …

    sishen authored
    …:controller/:action for url generator
This page is out of date. Refresh to see the latest.
View
5 actionpack/lib/action_controller/caching/actions.rb
@@ -116,9 +116,8 @@ def _save_fragment(name, options)
def expire_action(options = {})
return unless cache_configured?
- actions = options[:action]
- if actions.is_a?(Array)
- actions.each {|action| expire_action(options.merge(:action => action)) }
+ if options.is_a?(Hash) && options[:action].is_a?(Array)
+ options[:action].each {|action| expire_action(options.merge(:action => action)) }
else
expire_fragment(ActionCachePath.new(self, options, false).path)
end
View
29 actionpack/test/controller/caching_test.rb
@@ -245,6 +245,11 @@ def expire_xml
expire_action :controller => 'action_caching_test', :action => 'index', :format => 'xml'
render :nothing => true
end
+
+ def expire_custom_path
+ expire_action("http://test.host/custom/show")
+ render :nothing => true
+ end
end
class MockTime < Time
@@ -432,6 +437,30 @@ def test_cache_expiration_isnt_affected_by_request_format
assert_not_equal cached_time, @response.body
end
+ def test_cache_expiration_with_custom_cache_path
+ get :show
+ assert_response :success
+ cached_time = content_to_cache
+ reset!
+
+ get :show
+ assert_response :success
+ assert_equal cached_time, @response.body
+
+ get :expire_custom_path
+ assert_response :success
+ reset!
+
+ get :show
+ assert_response :success
+ new_cached_time = content_to_cache
+ assert_not_equal cached_time, @response.body
+
+ get :show
+ assert_response :success
+ assert_equal new_cached_time, @response.body
+ end
+
def test_cache_is_scoped_by_subdomain
@request.host = 'jamis.hostname.com'
get :index
Something went wrong with that request. Please try again.