Permalink
Browse files

Fixed Cache#expire_matched_fragments that couldn't recognize the diff…

…erence between string and url_for options #1030 [skaes@web.de]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1106 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent affe7c0 commit aefb36a68846bd86b3f20ff98a0e0013d117cb1a @dhh dhh committed Apr 7, 2005
Showing with 26 additions and 13 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +24 −13 actionpack/lib/action_controller/caching.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Fixed Cache#expire_matched_fragments that couldn't recognize the difference between string and url_for options #1030 [skaes@web.de]
+
* Added simulation of @request.request_uri in functional tests #1038 [Jamis Buck]
* Fixed autolinking to work better in more cases #1013 [Jamis Buck]
@@ -256,6 +256,15 @@ def self.append_features(base) #:nodoc:
end
end
+ def cache_base_url
+ @@cache_base_url ||= url_for(:controller => '')
+ end
+
+ def fragment_cache_key(name)
+ key = name.is_a?(Hash) ? url_for(name) : cache_base_url + name
+ key.split("://").last
+ end
+
# Called by CacheHelper#cache
def cache_erb_fragment(block, name = {}, options = {})
unless perform_caching then block.call; return end
@@ -272,31 +281,32 @@ def cache_erb_fragment(block, name = {}, options = {})
end
def write_fragment(name, content, options = {})
- name = url_for(name).split("://").last if name.is_a?(Hash)
- fragment_cache_store.write(name, content, options)
- logger.info "Cached fragment: #{name}" unless logger.nil?
+ key = fragment_cache_key(name)
+ fragment_cache_store.write(key, content, options)
+ logger.info "Cached fragment: #{key}" unless logger.nil?
content
end
def read_fragment(name, options = {})
- name = url_for(name).split("://").last if name.is_a?(Hash)
- if cache = fragment_cache_store.read(name, options)
- logger.info "Fragment hit: #{name}" unless logger.nil?
+ key = fragment_cache_key(name)
+ if cache = fragment_cache_store.read(key, options)
+ logger.info "Fragment hit: #{key}" unless logger.nil?
cache
else
false
end
end
def expire_fragment(name, options = {})
- name = url_for(name).split("://").last if name.is_a?(Hash)
- fragment_cache_store.delete(name, options)
- logger.info "Expired fragment: #{name}" unless logger.nil?
+ key = fragment_cache_key(name)
+ fragment_cache_store.delete(key, options)
+ logger.info "Expired fragment: #{key}" unless logger.nil?
end
- def expire_matched_fragments(re=Regexp.new('/*/'), options = {})
- fragment_cache_store.delete_matched(re, { :root_path => url_for.split('://').last.split('/').first })
- logger.info "Expired all fragments matching: #{re} " unless logger.nil?
+ def expire_matched_fragments(re=Regexp.new('/.*/'), options = {})
+ rp = cache_base_url
+ fragment_cache_store.delete_matched(re, { :root_path => rp })
+ logger.info "Expired all fragments matching: #{rp}#{re.source}" unless logger.nil?
end
class MemoryStore #:nodoc:
@@ -317,7 +327,8 @@ def delete(name, options = {}) #:nodoc:
end
def delete_matched(re, options) #:nodoc:
- @mutex.synchronize { @data.delete_if {|k,v| k.index(options[:root_path]) == 0 and k =~ re} }
+ re = Regexp.new("#{Regexp.escape(options[:root_path])}#{re.source}")
+ @mutex.synchronize { @data.delete_if { |k,v| k =~ re } }
end
end

0 comments on commit aefb36a

Please sign in to comment.