Permalink
Browse files

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
  • Loading branch information...
1 parent b0d69b1 commit df7a4d498c542a57d99622e160b3ede3d8b688a9 @dhh dhh committed Mar 26, 2005
Showing with 37 additions and 2 deletions.
  1. +4 −0 actionpack/CHANGELOG
  2. +33 −2 actionpack/lib/action_controller/caching.rb
View
@@ -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]
@@ -285,7 +285,12 @@ def expire_fragment(name, options = {})
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 @@ def write(name, value, options = {}) #: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 @@ def read(name, options = {}) #: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

0 comments on commit df7a4d4

Please sign in to comment.