Skip to content

Commit

Permalink
Fixed Cache#expire_matched_fragments that couldn't recognize the diff…
Browse files Browse the repository at this point in the history
…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
dhh committed Apr 7, 2005
1 parent affe7c0 commit aefb36a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN* *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] * Added simulation of @request.request_uri in functional tests #1038 [Jamis Buck]


* Fixed autolinking to work better in more cases #1013 [Jamis Buck] * Fixed autolinking to work better in more cases #1013 [Jamis Buck]
Expand Down
37 changes: 24 additions & 13 deletions actionpack/lib/action_controller/caching.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ def self.append_features(base) #:nodoc:
end end
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 # Called by CacheHelper#cache
def cache_erb_fragment(block, name = {}, options = {}) def cache_erb_fragment(block, name = {}, options = {})
unless perform_caching then block.call; return end unless perform_caching then block.call; return end
Expand All @@ -272,31 +281,32 @@ def cache_erb_fragment(block, name = {}, options = {})
end end


def write_fragment(name, content, options = {}) def write_fragment(name, content, options = {})
name = url_for(name).split("://").last if name.is_a?(Hash) key = fragment_cache_key(name)
fragment_cache_store.write(name, content, options) fragment_cache_store.write(key, content, options)
logger.info "Cached fragment: #{name}" unless logger.nil? logger.info "Cached fragment: #{key}" unless logger.nil?
content content
end end


def read_fragment(name, options = {}) def read_fragment(name, options = {})
name = url_for(name).split("://").last if name.is_a?(Hash) key = fragment_cache_key(name)
if cache = fragment_cache_store.read(name, options) if cache = fragment_cache_store.read(key, options)
logger.info "Fragment hit: #{name}" unless logger.nil? logger.info "Fragment hit: #{key}" unless logger.nil?
cache cache
else else
false false
end end
end end


def expire_fragment(name, options = {}) def expire_fragment(name, options = {})
name = url_for(name).split("://").last if name.is_a?(Hash) key = fragment_cache_key(name)
fragment_cache_store.delete(name, options) fragment_cache_store.delete(key, options)
logger.info "Expired fragment: #{name}" unless logger.nil? logger.info "Expired fragment: #{key}" unless logger.nil?
end end


def expire_matched_fragments(re=Regexp.new('/*/'), options = {}) def expire_matched_fragments(re=Regexp.new('/.*/'), options = {})
fragment_cache_store.delete_matched(re, { :root_path => url_for.split('://').last.split('/').first }) rp = cache_base_url
logger.info "Expired all fragments matching: #{re} " unless logger.nil? fragment_cache_store.delete_matched(re, { :root_path => rp })
logger.info "Expired all fragments matching: #{rp}#{re.source}" unless logger.nil?
end end


class MemoryStore #:nodoc: class MemoryStore #:nodoc:
Expand All @@ -317,7 +327,8 @@ def delete(name, options = {}) #:nodoc:
end end


def delete_matched(re, options) #:nodoc: 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
end end


Expand Down

0 comments on commit aefb36a

Please sign in to comment.