diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-26 13:09:56 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-26 13:09:56 +0000 |
commit | df7a4d498c542a57d99622e160b3ede3d8b688a9 (patch) | |
tree | 4a775b9404854ad3d3c8cf81c3ed53560d6c675d /actionpack | |
parent | b0d69b170f8bb7428846c46cf26bd0104d807100 (diff) | |
download | rails-df7a4d498c542a57d99622e160b3ede3d8b688a9.tar.gz rails-df7a4d498c542a57d99622e160b3ede3d8b688a9.tar.bz2 rails-df7a4d498c542a57d99622e160b3ede3d8b688a9.zip |
Added expire_matched_fragments(regular_expression) to clear out a lot of fragment caches at once #927 [technoweenie@gmail.com] Fixed the problems with : and ? in file names for fragment caches on Windows #927 [technoweenie@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@996 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/caching.rb | 35 |
2 files changed, 37 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index f4be0319e0..d0eeb05914 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,9 @@ *SVN* +* Added expire_matched_fragments(regular_expression) to clear out a lot of fragment caches at once #927 [technoweenie@gmail.com] + +* Fixed the problems with : and ? in file names for fragment caches on Windows #927 [technoweenie@gmail.com] + * Added TextHelper#human_size for formatting file sizes, like human_size(1234567) => 1.2 MB #943 [thomas@fesch.at] * Fixed link_to :confirm #936 [Nicholas Seckar] diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 4c11bc99d8..d071447c81 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -285,7 +285,12 @@ module ActionController #:nodoc: fragment_cache_store.delete(name, options) logger.info "Expired fragment: #{name}" 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? + end + class MemoryStore #:nodoc: def initialize @data, @mutex = { }, Mutex.new @@ -302,6 +307,10 @@ module ActionController #:nodoc: def delete(name, options = {}) #:nodoc: @mutex.synchronize { @data.delete(name) } end + + def delete_matched(re, options) #:nodoc: + @mutex.synchronize { @data.delete_if {|k,v| k.index(options[:root_path]) == 0 and k =~ re} } + end end class DRbStore < MemoryStore #:nodoc: @@ -335,15 +344,37 @@ module ActionController #:nodoc: def delete(name, options) #:nodoc: File.delete(real_file_path(name)) if File.exist?(real_file_path(name)) end + + def delete_matched(re, options) #:nodoc: + rootPath = real_file_path(options[:root_path]) + search_dir(@cache_path).each do |f| + File.delete(f) if f.index(rootPath) == 0 and f =~ re and File.exist?(f) + end + end private def real_file_path(name) - "#{@cache_path}/#{name}" + '%s/%s' % [@cache_path, name.gsub('?', '.').gsub(':', '.')] end def ensure_cache_path(path) FileUtils.makedirs(path) unless File.exists?(path) end + + def search_dir(dir) + require 'pathname' + files = [] + dir = Dir.new(dir) + dir.each do |d| + unless d == '.' or d == '..' + d = File.join(dir.path, d) + p = Pathname.new(d) + files << p.to_s if p.file? + files += search_dir(d) if p.directory? + end + end + files + end end end |