cache_trasher 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/cache_trasher.rb +58 -0
  2. metadata +63 -0
@@ -0,0 +1,58 @@
1
+ # CacheTrasher
2
+ module ActionController::Caching::Pages
3
+ module ClassMethods
4
+
5
+ def trash_cache(path, options)
6
+ puts "[CacheTrasher] ActionController::Base.perform_caching is disabled, exiting." and return unless perform_caching
7
+
8
+ # check if the action or controller has been saved as a cached file
9
+ # as opposed to just a directory.
10
+ paths = [path.chomp('/')]
11
+ # if options includes format(s), then use those, otherwise use the standard page_cache_extension to pick stuff up
12
+ if options[:format]
13
+ options[:format].to_a.each do |format|
14
+ paths << "#{paths[0]}.#{format}" if File.exist?("#{page_cache_directory}/#{paths[0]}.#{format}")
15
+ end
16
+ else
17
+ paths << "#{paths[0]}#{page_cache_extension}" if File.exist?("#{page_cache_directory}/#{paths[0]}#{page_cache_extension}")
18
+ end
19
+ paths.each do |p|
20
+ p = File.join(page_cache_directory, p)
21
+ unless [p, p.chomp, p.chomp('/'), p.chomp('/*')].include? Rails.public_path
22
+ puts "[CacheTrasher] Removing cache file or directory: #{p}"
23
+ begin
24
+ FileUtils.rm_r(p)
25
+ puts "[CacheTrasher] Expired #{p}"
26
+ rescue Errno::ENOENT
27
+ puts "[CacheTrasher] Failed to expire #{p}"
28
+ end
29
+ else
30
+ # drop a long message into the log if they try to delete RAILS_ROOT/public
31
+ puts "[CacheTrasher] Something is misconfigured. Check your environment log for more info."
32
+ File.open("#{RAILS_ROOT}/vendor/plugins/cache_trasher/warning.txt", 'r') { |f| logger.info f.read }
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ def trash_cache(supplied_path = "", options = {})
40
+ return unless perform_caching
41
+
42
+ path = case supplied_path
43
+ when Hash
44
+ # Note this part of the url_for documentation:
45
+ #
46
+ # If the controller name begins with a slash no defaults are used:
47
+ # url_for :controller => '/home'
48
+ # In particular, a leading slash ensures no namespace is assumed. Thus, while url_for :controller => 'users'
49
+ # may resolve to Admin::UsersController if the current controller lives under that module, url_for :controller => '/users'
50
+ # ensures you link to ::UsersController no matter what.
51
+ url_for(supplied_path.merge(:only_path => true, :skip_relative_url_root => true))
52
+ when String
53
+ supplied_path
54
+ end
55
+
56
+ self.class.trash_cache(path, options)
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cache_trasher
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Sean Roberts
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-02-07 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Convenience methods for removing page cache files in Rails
22
+ email:
23
+ - sean@factore.ca
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/cache_trasher.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/factore/cache_trasher
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.3.6
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Convenience methods for removing page cache files in Rails
62
+ test_files: []
63
+