cache_debugging 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile +29 -0
  5. data/LICENSE +20 -0
  6. data/README.md +104 -0
  7. data/Rakefile +32 -0
  8. data/cache_debugging.gemspec +20 -0
  9. data/lib/cache_debugging.rb +18 -0
  10. data/lib/cache_debugging/cache_blocks.rb +44 -0
  11. data/lib/cache_debugging/digestor.rb +3 -0
  12. data/lib/cache_debugging/railtie.rb +19 -0
  13. data/lib/cache_debugging/strict_dependencies.rb +47 -0
  14. data/lib/cache_debugging/utils.rb +40 -0
  15. data/lib/cache_debugging/version.rb +3 -0
  16. data/lib/cache_debugging/view_sampling.rb +80 -0
  17. data/test/dummy/README.rdoc +28 -0
  18. data/test/dummy/Rakefile +6 -0
  19. data/test/dummy/app/assets/images/.keep +0 -0
  20. data/test/dummy/app/assets/javascripts/application.js +13 -0
  21. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  22. data/test/dummy/app/controllers/application_controller.rb +10 -0
  23. data/test/dummy/app/controllers/concerns/.keep +0 -0
  24. data/test/dummy/app/controllers/workers_controller.rb +7 -0
  25. data/test/dummy/app/helpers/application_helper.rb +2 -0
  26. data/test/dummy/app/mailers/.keep +0 -0
  27. data/test/dummy/app/models/.keep +0 -0
  28. data/test/dummy/app/models/concerns/.keep +0 -0
  29. data/test/dummy/app/models/contract.rb +5 -0
  30. data/test/dummy/app/models/electrician.rb +3 -0
  31. data/test/dummy/app/models/gardener.rb +3 -0
  32. data/test/dummy/app/models/plumber.rb +3 -0
  33. data/test/dummy/app/models/tweet.rb +6 -0
  34. data/test/dummy/app/models/worker.rb +7 -0
  35. data/test/dummy/app/views/electricians/_electrician.html.erb +1 -0
  36. data/test/dummy/app/views/gardeners/_gardener.html.erb +1 -0
  37. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  38. data/test/dummy/app/views/plumbers/_plumber.html.erb +1 -0
  39. data/test/dummy/app/views/workers/_tweets.html.erb +5 -0
  40. data/test/dummy/app/views/workers/_worker.html.erb +12 -0
  41. data/test/dummy/app/views/workers/index.html.erb +17 -0
  42. data/test/dummy/bin/bundle +3 -0
  43. data/test/dummy/bin/rails +4 -0
  44. data/test/dummy/bin/rake +4 -0
  45. data/test/dummy/config.ru +4 -0
  46. data/test/dummy/config/application.rb +27 -0
  47. data/test/dummy/config/boot.rb +5 -0
  48. data/test/dummy/config/database.yml +25 -0
  49. data/test/dummy/config/environment.rb +5 -0
  50. data/test/dummy/config/environments/development.rb +29 -0
  51. data/test/dummy/config/environments/production.rb +80 -0
  52. data/test/dummy/config/environments/test.rb +36 -0
  53. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/test/dummy/config/initializers/caching.rb +32 -0
  55. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  56. data/test/dummy/config/initializers/inflections.rb +16 -0
  57. data/test/dummy/config/initializers/mime_types.rb +5 -0
  58. data/test/dummy/config/initializers/secret_token.rb +16 -0
  59. data/test/dummy/config/initializers/session_store.rb +3 -0
  60. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  61. data/test/dummy/config/locales/en.yml +23 -0
  62. data/test/dummy/config/routes.rb +3 -0
  63. data/test/dummy/db/migrate/20130910001826_create_workers.rb +36 -0
  64. data/test/dummy/db/schema.rb +55 -0
  65. data/test/dummy/lib/assets/.keep +0 -0
  66. data/test/dummy/log/.keep +0 -0
  67. data/test/dummy/public/404.html +58 -0
  68. data/test/dummy/public/422.html +58 -0
  69. data/test/dummy/public/500.html +57 -0
  70. data/test/dummy/public/favicon.ico +0 -0
  71. data/test/dummy/test/fixtures/electricians.yml +2 -0
  72. data/test/dummy/test/fixtures/gardeners.yml +2 -0
  73. data/test/dummy/test/fixtures/plumbers.yml +2 -0
  74. data/test/dummy/test/fixtures/workers.yml +17 -0
  75. data/test/integration/cache_debugging_test.rb +81 -0
  76. data/test/test_helper.rb +17 -0
  77. metadata +146 -0
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,32 @@
1
+ class TemplateDependencyException < Exception
2
+ def initialize(partial, template, dependencies)
3
+ @partial = partial
4
+ @template = template
5
+ @dependencies = dependencies
6
+ end
7
+
8
+ def message
9
+ %{#{@partial} not in template cache dependency tree for #{@template}: #{@dependencies.inspect}"}
10
+ end
11
+ end
12
+
13
+ class CacheMismatchException < Exception
14
+ def initialize(template, cache_key)
15
+ @template = template
16
+ @cache_key = cache_key
17
+ end
18
+
19
+ def message
20
+ %{Cache mismatch: #{@template}, #{@cache_key}}
21
+ end
22
+ end
23
+
24
+ ActiveSupport::Notifications.subscribe 'cache_debugging.cache_dependency_missing' do |*args|
25
+ event = ActiveSupport::Notifications::Event.new(*args)
26
+ raise TemplateDependencyException.new(event.payload[:partial], event.payload[:template], event.payload[:dependencies])
27
+ end
28
+
29
+ ActiveSupport::Notifications.subscribe 'cache_debugging.cache_mismatch' do |*args|
30
+ event = ActiveSupport::Notifications::Event.new(*args)
31
+ raise CacheMismatchException.new(event.payload[:template], event.payload[:cache_key])
32
+ end
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, '\1en'
8
+ # inflect.singular /^(ox)en/i, '\1'
9
+ # inflect.irregular 'person', 'people'
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure your secret_key_base is kept private
11
+ # if you're sharing your code publicly.
12
+ if Rails::VERSION::MAJOR == 4
13
+ Dummy::Application.config.secret_key_base = '4adc573725714bbd95224181f48aa3cc22055e9995c73e3a2a6f2e899281c92423ad082543254d79a711298416a8cc7d3d486d5b7ad5874c72dfcc3ac9645d7f'
14
+ else
15
+ Dummy::Application.config.secret_token = '4adc573725714bbd95224181f48aa3cc22055e9995c73e3a2a6f2e899281c92423ad082543254d79a711298416a8cc7d3d486d5b7ad5874c72dfcc3ac9645d7f'
16
+ end
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
+ end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -0,0 +1,23 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ hello: "Hello world"
@@ -0,0 +1,3 @@
1
+ Dummy::Application.routes.draw do
2
+ resources :workers
3
+ end
@@ -0,0 +1,36 @@
1
+ class CreateWorkers < ActiveRecord::Migration
2
+ def change
3
+ create_table :workers do |t|
4
+ t.string :name
5
+ t.string :detail_type
6
+ t.integer :detail_id
7
+ t.timestamps
8
+ end
9
+
10
+ create_table :plumbers do |t|
11
+ t.boolean :has_wrench
12
+ t.timestamps
13
+ end
14
+
15
+ create_table :gardeners do |t|
16
+ t.boolean :has_shovel
17
+ t.timestamps
18
+ end
19
+
20
+ create_table :electricians do |t|
21
+ t.boolean :certified
22
+ t.timestamps
23
+ end
24
+
25
+ create_table :contracts do |t|
26
+ t.belongs_to :worker
27
+ t.timestamps
28
+ end
29
+
30
+ create_table :tweets do |t|
31
+ t.belongs_to :worker
32
+ t.string :message
33
+ t.timestamps
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20130910001826) do
15
+
16
+ create_table "contracts", force: true do |t|
17
+ t.integer "worker_id"
18
+ t.datetime "created_at"
19
+ t.datetime "updated_at"
20
+ end
21
+
22
+ create_table "electricians", force: true do |t|
23
+ t.boolean "certified"
24
+ t.datetime "created_at"
25
+ t.datetime "updated_at"
26
+ end
27
+
28
+ create_table "gardeners", force: true do |t|
29
+ t.boolean "has_shovel"
30
+ t.datetime "created_at"
31
+ t.datetime "updated_at"
32
+ end
33
+
34
+ create_table "plumbers", force: true do |t|
35
+ t.boolean "has_wrench"
36
+ t.datetime "created_at"
37
+ t.datetime "updated_at"
38
+ end
39
+
40
+ create_table "tweets", force: true do |t|
41
+ t.integer "worker_id"
42
+ t.string "message"
43
+ t.datetime "created_at"
44
+ t.datetime "updated_at"
45
+ end
46
+
47
+ create_table "workers", force: true do |t|
48
+ t.string "name"
49
+ t.string "detail_type"
50
+ t.integer "detail_id"
51
+ t.datetime "created_at"
52
+ t.datetime "updated_at"
53
+ end
54
+
55
+ end
File without changes
File without changes
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,2 @@
1
+ eric:
2
+ certified: 1
@@ -0,0 +1,2 @@
1
+ george:
2
+ has_shovel: 1
@@ -0,0 +1,2 @@
1
+ pete:
2
+ has_wrench: 1
@@ -0,0 +1,17 @@
1
+ pete:
2
+ name: "Pete the Plumber"
3
+ detail_type: "Plumber"
4
+ detail_id: <%= ActiveRecord::Fixtures.identify(:pete) %>
5
+ updated_at: <%= Time.now - 10 %>
6
+
7
+ george:
8
+ name: "George the Gardener"
9
+ detail_type: "Gardener"
10
+ detail_id: <%= ActiveRecord::Fixtures.identify(:george) %>
11
+ updated_at: <%= Time.now - 10 %>
12
+
13
+ eric:
14
+ name: "Eric the Electrician"
15
+ detail_type: "Electrician"
16
+ detail_id: <%= ActiveRecord::Fixtures.identify(:eric) %>
17
+ updated_at: <%= Time.now - 10 %>