From 5640f76970c9b68f74df9da5cfa9763833e00d78 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 30 Apr 2005 08:23:42 +0000 Subject: Improved the speed of regular expression expirations for caching by a factor of 10 #1221 [Jamis Buck] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1248 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/caching.rb | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 0254c2d98d..92eb8770df 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -368,8 +368,8 @@ module ActionController #:nodoc: end def delete_matched(matcher, options) #:nodoc: - search_dir(@cache_path).each do |f| - File.delete(f) if f =~ matcher && File.exist?(f) + search_dir(@cache_path) do |f| + File.delete(f) rescue nil if f =~ matcher end end @@ -382,19 +382,16 @@ module ActionController #:nodoc: 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? + def search_dir(dir, &callback) + Dir.foreach(dir) do |d| + next if d == "." || d == ".." + name = File.join(dir, d) + if File.directory?(name) + search_dir(name, &callback) + else + callback.call name end end - files end end end -- cgit v1.2.3