5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/cache_trasher.rb', line 5
def trash_cache(path, options)
puts "[CacheTrasher] ActionController::Base.perform_caching is disabled, exiting." and return unless perform_caching
paths = [path.chomp('/')]
if options[:format]
options[:format].to_a.each do |format|
paths << "#{paths[0]}.#{format}" if File.exist?("#{page_cache_directory}/#{paths[0]}.#{format}")
end
else
paths << "#{paths[0]}#{page_cache_extension}" if File.exist?("#{page_cache_directory}/#{paths[0]}#{page_cache_extension}")
end
paths.each do |p|
p = File.join(page_cache_directory, p)
unless [p, p.chomp, p.chomp('/'), p.chomp('/*')].include? Rails.public_path
puts "[CacheTrasher] Removing cache file or directory: #{p}"
begin
FileUtils.rm_r(p)
puts "[CacheTrasher] Expired #{p}"
rescue Errno::ENOENT
puts "[CacheTrasher] Failed to expire #{p}"
end
else
puts "[CacheTrasher] Something is misconfigured. Check your environment log for more info."
File.open("#{RAILS_ROOT}/vendor/plugins/cache_trasher/warning.txt", 'r') { |f| logger.info f.read }
end
end
end
|