rails 2.2.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rails might be problematic. Click here for more details.
- data/bin/rails +8 -18
- metadata +118 -452
- data/CHANGELOG +0 -2071
- data/MIT-LICENSE +0 -20
- data/README +0 -256
- data/Rakefile +0 -411
- data/bin/about +0 -4
- data/bin/console +0 -3
- data/bin/dbconsole +0 -3
- data/bin/destroy +0 -3
- data/bin/generate +0 -3
- data/bin/performance/benchmarker +0 -3
- data/bin/performance/profiler +0 -3
- data/bin/performance/request +0 -3
- data/bin/plugin +0 -3
- data/bin/process/inspector +0 -3
- data/bin/process/reaper +0 -3
- data/bin/process/spawner +0 -3
- data/bin/runner +0 -3
- data/bin/server +0 -3
- data/builtin/rails_info/rails/info.rb +0 -125
- data/builtin/rails_info/rails/info_controller.rb +0 -9
- data/builtin/rails_info/rails/info_helper.rb +0 -2
- data/builtin/rails_info/rails_info_controller.rb +0 -2
- data/config.ru +0 -17
- data/configs/apache.conf +0 -40
- data/configs/databases/frontbase.yml +0 -28
- data/configs/databases/ibm_db.yml +0 -62
- data/configs/databases/mysql.yml +0 -57
- data/configs/databases/oracle.yml +0 -39
- data/configs/databases/postgresql.yml +0 -51
- data/configs/databases/sqlite2.yml +0 -19
- data/configs/databases/sqlite3.yml +0 -22
- data/configs/empty.log +0 -0
- data/configs/initializers/inflections.rb +0 -10
- data/configs/initializers/mime_types.rb +0 -5
- data/configs/initializers/new_rails_defaults.rb +0 -17
- data/configs/lighttpd.conf +0 -54
- data/configs/locales/en.yml +0 -5
- data/configs/routes.rb +0 -43
- data/dispatches/dispatch.fcgi +0 -24
- data/dispatches/dispatch.rb +0 -10
- data/dispatches/gateway.cgi +0 -97
- data/doc/README_FOR_APP +0 -5
- data/doc/guides/html/2_2_release_notes.html +0 -1185
- data/doc/guides/html/actioncontroller_basics.html +0 -1270
- data/doc/guides/html/activerecord_validations_callbacks.html +0 -749
- data/doc/guides/html/association_basics.html +0 -2585
- data/doc/guides/html/authors.html +0 -240
- data/doc/guides/html/benchmarking_and_profiling.html +0 -1018
- data/doc/guides/html/caching_with_rails.html +0 -583
- data/doc/guides/html/command_line.html +0 -434
- data/doc/guides/html/configuring.html +0 -438
- data/doc/guides/html/creating_plugins.html +0 -1594
- data/doc/guides/html/debugging_rails_applications.html +0 -1175
- data/doc/guides/html/finders.html +0 -1090
- data/doc/guides/html/form_helpers.html +0 -638
- data/doc/guides/html/getting_started_with_rails.html +0 -2066
- data/doc/guides/html/index.html +0 -349
- data/doc/guides/html/layouts_and_rendering.html +0 -1406
- data/doc/guides/html/migrations.html +0 -921
- data/doc/guides/html/routing_outside_in.html +0 -2213
- data/doc/guides/html/security.html +0 -1346
- data/doc/guides/html/testing_rails_applications.html +0 -1859
- data/doc/guides/source/2_2_release_notes.txt +0 -435
- data/doc/guides/source/actioncontroller_basics/changelog.txt +0 -5
- data/doc/guides/source/actioncontroller_basics/cookies.txt +0 -34
- data/doc/guides/source/actioncontroller_basics/csrf.txt +0 -32
- data/doc/guides/source/actioncontroller_basics/filters.txt +0 -119
- data/doc/guides/source/actioncontroller_basics/http_auth.txt +0 -24
- data/doc/guides/source/actioncontroller_basics/index.txt +0 -40
- data/doc/guides/source/actioncontroller_basics/introduction.txt +0 -9
- data/doc/guides/source/actioncontroller_basics/methods.txt +0 -39
- data/doc/guides/source/actioncontroller_basics/parameter_filtering.txt +0 -14
- data/doc/guides/source/actioncontroller_basics/params.txt +0 -93
- data/doc/guides/source/actioncontroller_basics/request_response_objects.txt +0 -43
- data/doc/guides/source/actioncontroller_basics/rescue.txt +0 -67
- data/doc/guides/source/actioncontroller_basics/session.txt +0 -187
- data/doc/guides/source/actioncontroller_basics/streaming.txt +0 -91
- data/doc/guides/source/actioncontroller_basics/verification.txt +0 -40
- data/doc/guides/source/active_record_basics.txt +0 -181
- data/doc/guides/source/activerecord_validations_callbacks.txt +0 -404
- data/doc/guides/source/association_basics.txt +0 -1840
- data/doc/guides/source/authors.txt +0 -39
- data/doc/guides/source/benchmarking_and_profiling/appendix.txt +0 -95
- data/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt +0 -105
- data/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt +0 -185
- data/doc/guides/source/benchmarking_and_profiling/gameplan.txt +0 -27
- data/doc/guides/source/benchmarking_and_profiling/index.txt +0 -242
- data/doc/guides/source/benchmarking_and_profiling/rubyprof.txt +0 -179
- data/doc/guides/source/benchmarking_and_profiling/statistics.txt +0 -57
- data/doc/guides/source/caching_with_rails.txt +0 -367
- data/doc/guides/source/command_line.txt +0 -147
- data/doc/guides/source/configuring.txt +0 -225
- data/doc/guides/source/creating_plugins/acts_as_yaffle.txt +0 -191
- data/doc/guides/source/creating_plugins/appendix.txt +0 -46
- data/doc/guides/source/creating_plugins/controllers.txt +0 -59
- data/doc/guides/source/creating_plugins/core_ext.txt +0 -123
- data/doc/guides/source/creating_plugins/custom_route.txt +0 -69
- data/doc/guides/source/creating_plugins/gem.txt +0 -1
- data/doc/guides/source/creating_plugins/generator_method.txt +0 -89
- data/doc/guides/source/creating_plugins/helpers.txt +0 -51
- data/doc/guides/source/creating_plugins/index.txt +0 -52
- data/doc/guides/source/creating_plugins/migration_generator.txt +0 -156
- data/doc/guides/source/creating_plugins/models.txt +0 -76
- data/doc/guides/source/creating_plugins/odds_and_ends.txt +0 -69
- data/doc/guides/source/creating_plugins/test_setup.txt +0 -230
- data/doc/guides/source/debugging_rails_applications.txt +0 -733
- data/doc/guides/source/finders.txt +0 -668
- data/doc/guides/source/form_helpers.txt +0 -345
- data/doc/guides/source/getting_started_with_rails.txt +0 -1256
- data/doc/guides/source/images/belongs_to.png +0 -0
- data/doc/guides/source/images/bullet.gif +0 -0
- data/doc/guides/source/images/csrf.png +0 -0
- data/doc/guides/source/images/habtm.png +0 -0
- data/doc/guides/source/images/has_many.png +0 -0
- data/doc/guides/source/images/has_many_through.png +0 -0
- data/doc/guides/source/images/has_one.png +0 -0
- data/doc/guides/source/images/has_one_through.png +0 -0
- data/doc/guides/source/images/header_backdrop.png +0 -0
- data/doc/guides/source/images/icons/README +0 -5
- data/doc/guides/source/images/icons/callouts/1.png +0 -0
- data/doc/guides/source/images/icons/callouts/10.png +0 -0
- data/doc/guides/source/images/icons/callouts/11.png +0 -0
- data/doc/guides/source/images/icons/callouts/12.png +0 -0
- data/doc/guides/source/images/icons/callouts/13.png +0 -0
- data/doc/guides/source/images/icons/callouts/14.png +0 -0
- data/doc/guides/source/images/icons/callouts/15.png +0 -0
- data/doc/guides/source/images/icons/callouts/2.png +0 -0
- data/doc/guides/source/images/icons/callouts/3.png +0 -0
- data/doc/guides/source/images/icons/callouts/4.png +0 -0
- data/doc/guides/source/images/icons/callouts/5.png +0 -0
- data/doc/guides/source/images/icons/callouts/6.png +0 -0
- data/doc/guides/source/images/icons/callouts/7.png +0 -0
- data/doc/guides/source/images/icons/callouts/8.png +0 -0
- data/doc/guides/source/images/icons/callouts/9.png +0 -0
- data/doc/guides/source/images/icons/caution.png +0 -0
- data/doc/guides/source/images/icons/example.png +0 -0
- data/doc/guides/source/images/icons/home.png +0 -0
- data/doc/guides/source/images/icons/important.png +0 -0
- data/doc/guides/source/images/icons/next.png +0 -0
- data/doc/guides/source/images/icons/note.png +0 -0
- data/doc/guides/source/images/icons/prev.png +0 -0
- data/doc/guides/source/images/icons/tip.png +0 -0
- data/doc/guides/source/images/icons/up.png +0 -0
- data/doc/guides/source/images/icons/warning.png +0 -0
- data/doc/guides/source/images/polymorphic.png +0 -0
- data/doc/guides/source/images/rails_logo_remix.gif +0 -0
- data/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif +0 -0
- data/doc/guides/source/images/session_fixation.png +0 -0
- data/doc/guides/source/index.txt +0 -118
- data/doc/guides/source/layouts_and_rendering.txt +0 -982
- data/doc/guides/source/migrations/anatomy_of_a_migration.txt +0 -85
- data/doc/guides/source/migrations/changelog.txt +0 -5
- data/doc/guides/source/migrations/creating_a_migration.txt +0 -109
- data/doc/guides/source/migrations/foreign_keys.txt +0 -8
- data/doc/guides/source/migrations/index.txt +0 -22
- data/doc/guides/source/migrations/rakeing_around.txt +0 -111
- data/doc/guides/source/migrations/scheming.txt +0 -47
- data/doc/guides/source/migrations/using_models_in_migrations.txt +0 -46
- data/doc/guides/source/migrations/writing_a_migration.txt +0 -159
- data/doc/guides/source/routing_outside_in.txt +0 -986
- data/doc/guides/source/security.txt +0 -984
- data/doc/guides/source/stylesheets/base.css +0 -358
- data/doc/guides/source/stylesheets/forms.css +0 -35
- data/doc/guides/source/stylesheets/more.css +0 -82
- data/doc/guides/source/templates/guides.html.erb +0 -97
- data/doc/guides/source/templates/inline.css +0 -165
- data/doc/guides/source/testing_rails_applications.txt +0 -995
- data/environments/boot.rb +0 -109
- data/environments/development.rb +0 -17
- data/environments/environment.rb +0 -75
- data/environments/production.rb +0 -24
- data/environments/test.rb +0 -22
- data/fresh_rakefile +0 -10
- data/helpers/application.rb +0 -15
- data/helpers/application_helper.rb +0 -3
- data/helpers/performance_test.rb +0 -9
- data/helpers/test_helper.rb +0 -38
- data/html/404.html +0 -30
- data/html/422.html +0 -30
- data/html/500.html +0 -33
- data/html/favicon.ico +0 -0
- data/html/images/rails.png +0 -0
- data/html/index.html +0 -274
- data/html/javascripts/application.js +0 -2
- data/html/javascripts/controls.js +0 -963
- data/html/javascripts/dragdrop.js +0 -973
- data/html/javascripts/effects.js +0 -1128
- data/html/javascripts/prototype.js +0 -4320
- data/html/robots.txt +0 -5
- data/lib/code_statistics.rb +0 -107
- data/lib/commands.rb +0 -17
- data/lib/commands/about.rb +0 -3
- data/lib/commands/console.rb +0 -45
- data/lib/commands/dbconsole.rb +0 -67
- data/lib/commands/destroy.rb +0 -6
- data/lib/commands/generate.rb +0 -6
- data/lib/commands/ncgi/listener +0 -86
- data/lib/commands/ncgi/tracker +0 -69
- data/lib/commands/performance/benchmarker.rb +0 -24
- data/lib/commands/performance/profiler.rb +0 -50
- data/lib/commands/performance/request.rb +0 -6
- data/lib/commands/plugin.rb +0 -967
- data/lib/commands/process/inspector.rb +0 -68
- data/lib/commands/process/reaper.rb +0 -149
- data/lib/commands/process/spawner.rb +0 -219
- data/lib/commands/process/spinner.rb +0 -57
- data/lib/commands/runner.rb +0 -48
- data/lib/commands/server.rb +0 -49
- data/lib/commands/servers/base.rb +0 -31
- data/lib/commands/servers/lighttpd.rb +0 -94
- data/lib/commands/servers/mongrel.rb +0 -69
- data/lib/commands/servers/new_mongrel.rb +0 -16
- data/lib/commands/servers/thin.rb +0 -25
- data/lib/commands/servers/webrick.rb +0 -66
- data/lib/commands/update.rb +0 -4
- data/lib/console_app.rb +0 -30
- data/lib/console_sandbox.rb +0 -6
- data/lib/console_with_helpers.rb +0 -26
- data/lib/dispatcher.rb +0 -24
- data/lib/fcgi_handler.rb +0 -237
- data/lib/initializer.rb +0 -1038
- data/lib/performance_test_help.rb +0 -5
- data/lib/rails/gem_builder.rb +0 -21
- data/lib/rails/gem_dependency.rb +0 -251
- data/lib/rails/mongrel_server/commands.rb +0 -342
- data/lib/rails/mongrel_server/handler.rb +0 -55
- data/lib/rails/plugin.rb +0 -124
- data/lib/rails/plugin/loader.rb +0 -152
- data/lib/rails/plugin/locator.rb +0 -100
- data/lib/rails/rack.rb +0 -6
- data/lib/rails/rack/logger.rb +0 -28
- data/lib/rails/rack/static.rb +0 -35
- data/lib/rails/vendor_gem_source_index.rb +0 -140
- data/lib/rails/version.rb +0 -9
- data/lib/rails_generator.rb +0 -43
- data/lib/rails_generator/base.rb +0 -263
- data/lib/rails_generator/commands.rb +0 -616
- data/lib/rails_generator/generated_attribute.rb +0 -46
- data/lib/rails_generator/generators/applications/app/USAGE +0 -9
- data/lib/rails_generator/generators/applications/app/app_generator.rb +0 -184
- data/lib/rails_generator/generators/components/controller/USAGE +0 -29
- data/lib/rails_generator/generators/components/controller/controller_generator.rb +0 -37
- data/lib/rails_generator/generators/components/controller/templates/controller.rb +0 -7
- data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +0 -8
- data/lib/rails_generator/generators/components/controller/templates/helper.rb +0 -2
- data/lib/rails_generator/generators/components/controller/templates/view.html.erb +0 -2
- data/lib/rails_generator/generators/components/integration_test/USAGE +0 -8
- data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +0 -16
- data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +0 -10
- data/lib/rails_generator/generators/components/mailer/USAGE +0 -16
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +0 -30
- data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +0 -3
- data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -0
- data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +0 -15
- data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +0 -20
- data/lib/rails_generator/generators/components/mailer/templates/view.erb +0 -3
- data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -0
- data/lib/rails_generator/generators/components/migration/USAGE +0 -29
- data/lib/rails_generator/generators/components/migration/migration_generator.rb +0 -20
- data/lib/rails_generator/generators/components/migration/templates/migration.rb +0 -11
- data/lib/rails_generator/generators/components/model/USAGE +0 -27
- data/lib/rails_generator/generators/components/model/model_generator.rb +0 -45
- data/lib/rails_generator/generators/components/model/templates/fixtures.yml +0 -19
- data/lib/rails_generator/generators/components/model/templates/migration.rb +0 -16
- data/lib/rails_generator/generators/components/model/templates/model.rb +0 -5
- data/lib/rails_generator/generators/components/model/templates/unit_test.rb +0 -8
- data/lib/rails_generator/generators/components/observer/USAGE +0 -13
- data/lib/rails_generator/generators/components/observer/observer_generator.rb +0 -16
- data/lib/rails_generator/generators/components/observer/templates/observer.rb +0 -2
- data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -8
- data/lib/rails_generator/generators/components/performance_test/USAGE +0 -8
- data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +0 -16
- data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +0 -9
- data/lib/rails_generator/generators/components/plugin/USAGE +0 -25
- data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +0 -39
- data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +0 -20
- data/lib/rails_generator/generators/components/plugin/templates/README +0 -13
- data/lib/rails_generator/generators/components/plugin/templates/Rakefile +0 -23
- data/lib/rails_generator/generators/components/plugin/templates/USAGE +0 -8
- data/lib/rails_generator/generators/components/plugin/templates/generator.rb +0 -8
- data/lib/rails_generator/generators/components/plugin/templates/init.rb +0 -1
- data/lib/rails_generator/generators/components/plugin/templates/install.rb +0 -1
- data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +0 -1
- data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +0 -4
- data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +0 -3
- data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +0 -1
- data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +0 -8
- data/lib/rails_generator/generators/components/resource/USAGE +0 -23
- data/lib/rails_generator/generators/components/resource/resource_generator.rb +0 -74
- data/lib/rails_generator/generators/components/resource/templates/controller.rb +0 -2
- data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +0 -8
- data/lib/rails_generator/generators/components/resource/templates/helper.rb +0 -2
- data/lib/rails_generator/generators/components/scaffold/USAGE +0 -29
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -100
- data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +0 -85
- data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +0 -45
- data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +0 -2
- data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +0 -17
- data/lib/rails_generator/generators/components/scaffold/templates/style.css +0 -54
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +0 -18
- data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +0 -24
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +0 -17
- data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +0 -10
- data/lib/rails_generator/generators/components/session_migration/USAGE +0 -10
- data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +0 -18
- data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +0 -16
- data/lib/rails_generator/lookup.rb +0 -249
- data/lib/rails_generator/manifest.rb +0 -53
- data/lib/rails_generator/options.rb +0 -150
- data/lib/rails_generator/scripts.rb +0 -89
- data/lib/rails_generator/scripts/destroy.rb +0 -29
- data/lib/rails_generator/scripts/generate.rb +0 -7
- data/lib/rails_generator/scripts/update.rb +0 -12
- data/lib/rails_generator/secret_key_generator.rb +0 -22
- data/lib/rails_generator/simple_logger.rb +0 -46
- data/lib/rails_generator/spec.rb +0 -44
- data/lib/railties_path.rb +0 -1
- data/lib/ruby_version_check.rb +0 -17
- data/lib/rubyprof_ext.rb +0 -35
- data/lib/source_annotation_extractor.rb +0 -102
- data/lib/tasks/annotations.rake +0 -20
- data/lib/tasks/databases.rake +0 -416
- data/lib/tasks/documentation.rake +0 -95
- data/lib/tasks/framework.rake +0 -118
- data/lib/tasks/gems.rake +0 -80
- data/lib/tasks/log.rake +0 -9
- data/lib/tasks/misc.rake +0 -56
- data/lib/tasks/rails.rb +0 -8
- data/lib/tasks/routes.rake +0 -17
- data/lib/tasks/statistics.rake +0 -18
- data/lib/tasks/testing.rake +0 -139
- data/lib/tasks/tmp.rake +0 -37
- data/lib/test_help.rb +0 -27
- data/lib/webrick_server.rb +0 -156
@@ -1,583 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
-
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
3
|
-
<head>
|
4
|
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
5
|
-
<title>Caching with Rails: An overview</title>
|
6
|
-
<!--[if lt IE 8]>
|
7
|
-
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
|
8
|
-
<![endif]-->
|
9
|
-
<link href="stylesheets/base.css" media="screen" rel="Stylesheet" type="text/css" />
|
10
|
-
<link href="stylesheets/forms.css" media="screen" rel="Stylesheet" type="text/css" />
|
11
|
-
<link href="stylesheets/more.css" media="screen" rel="Stylesheet" type="text/css" />
|
12
|
-
<style type="text/css">
|
13
|
-
div#container {
|
14
|
-
max-width: 900px;
|
15
|
-
padding-bottom: 3em;
|
16
|
-
}
|
17
|
-
|
18
|
-
div#content {
|
19
|
-
margin-left: 200px;
|
20
|
-
}
|
21
|
-
|
22
|
-
div#container.notoc {
|
23
|
-
max-width: 600px;
|
24
|
-
}
|
25
|
-
|
26
|
-
.notoc div#content {
|
27
|
-
margin-left: 0;
|
28
|
-
}
|
29
|
-
|
30
|
-
pre {
|
31
|
-
line-height: 1.4em;
|
32
|
-
}
|
33
|
-
|
34
|
-
#content p tt {
|
35
|
-
background: #eeeeee;
|
36
|
-
border: solid 1px #cccccc;
|
37
|
-
padding: 3px;
|
38
|
-
}
|
39
|
-
|
40
|
-
dt {
|
41
|
-
font-weight: bold;
|
42
|
-
}
|
43
|
-
|
44
|
-
#content dt tt {
|
45
|
-
font-size: 10pt;
|
46
|
-
}
|
47
|
-
|
48
|
-
dd {
|
49
|
-
margin-left: 3em;
|
50
|
-
}
|
51
|
-
|
52
|
-
#content dt tt, #content pre tt {
|
53
|
-
background: none;
|
54
|
-
padding: 0;
|
55
|
-
border: 0;
|
56
|
-
}
|
57
|
-
|
58
|
-
#content .olist ol {
|
59
|
-
margin-left: 2em;
|
60
|
-
}
|
61
|
-
|
62
|
-
#header {
|
63
|
-
position: relative;
|
64
|
-
max-width: 840px;
|
65
|
-
margin-left: auto;
|
66
|
-
margin-right: auto;
|
67
|
-
}
|
68
|
-
|
69
|
-
#header.notoc {
|
70
|
-
max-width: 580px;
|
71
|
-
}
|
72
|
-
|
73
|
-
#logo {
|
74
|
-
position: absolute;
|
75
|
-
left: 10px;
|
76
|
-
top: 10px;
|
77
|
-
width: 110px;
|
78
|
-
height: 140px;
|
79
|
-
}
|
80
|
-
|
81
|
-
div#header h1#site_title {
|
82
|
-
background: url('images/ruby_on_rails_by_mike_rundle2.gif') top left no-repeat;
|
83
|
-
position: absolute;
|
84
|
-
width: 392px;
|
85
|
-
height: 55px;
|
86
|
-
left: 145px;
|
87
|
-
top: 20px;
|
88
|
-
margin: 0;
|
89
|
-
padding: 0;
|
90
|
-
}
|
91
|
-
|
92
|
-
#site_title span {
|
93
|
-
display: none;
|
94
|
-
}
|
95
|
-
|
96
|
-
#site_title_tagline {
|
97
|
-
display: none;
|
98
|
-
}
|
99
|
-
|
100
|
-
ul#navMain {
|
101
|
-
position: absolute;
|
102
|
-
margin: 0;
|
103
|
-
padding: 0;
|
104
|
-
top: 97px;
|
105
|
-
left: 145px;
|
106
|
-
}
|
107
|
-
|
108
|
-
.left-floaty, .right-floaty {
|
109
|
-
padding: 15px;
|
110
|
-
}
|
111
|
-
|
112
|
-
.admonitionblock,
|
113
|
-
.tableblock {
|
114
|
-
margin-left: 1em;
|
115
|
-
margin-right: 1em;
|
116
|
-
margin-top: 0.25em;
|
117
|
-
margin-bottom: 1em;
|
118
|
-
}
|
119
|
-
|
120
|
-
.admonitionblock .icon {
|
121
|
-
padding-right: 8px;
|
122
|
-
}
|
123
|
-
|
124
|
-
.admonitionblock .content {
|
125
|
-
border: solid 1px #ffda78;
|
126
|
-
background: #fffebd;
|
127
|
-
padding: 10px;
|
128
|
-
padding-top: 8px;
|
129
|
-
padding-bottom: 8px;
|
130
|
-
}
|
131
|
-
|
132
|
-
.admonitionblock .title {
|
133
|
-
font-size: 140%;
|
134
|
-
margin-bottom: 0.5em;
|
135
|
-
}
|
136
|
-
|
137
|
-
.tableblock table {
|
138
|
-
border: solid 1px #aaaaff;
|
139
|
-
background: #f0f0ff;
|
140
|
-
}
|
141
|
-
|
142
|
-
.tableblock th {
|
143
|
-
background: #e0e0e0;
|
144
|
-
}
|
145
|
-
|
146
|
-
.tableblock th,
|
147
|
-
.tableblock td {
|
148
|
-
padding: 3px;
|
149
|
-
padding-left: 5px;
|
150
|
-
padding-right: 5px;
|
151
|
-
}
|
152
|
-
|
153
|
-
.sidebarblock {
|
154
|
-
margin-top: 0.25em;
|
155
|
-
margin: 1em;
|
156
|
-
border: solid 1px #ccccbb;
|
157
|
-
padding: 8px;
|
158
|
-
background: #ffffe0;
|
159
|
-
}
|
160
|
-
|
161
|
-
.sidebarblock .sidebar-title {
|
162
|
-
font-size: 140%;
|
163
|
-
font-weight: 600;
|
164
|
-
margin-bottom: 0.3em;
|
165
|
-
}
|
166
|
-
|
167
|
-
.sidebarblock .sidebar-content > .para:last-child > p {
|
168
|
-
margin-bottom: 0;
|
169
|
-
}
|
170
|
-
|
171
|
-
.sidebarblock .sidebar-title a {
|
172
|
-
text-decoration: none;
|
173
|
-
}
|
174
|
-
|
175
|
-
.sidebarblock .sidebar-title a:hover {
|
176
|
-
text-decoration: underline;
|
177
|
-
}
|
178
|
-
|
179
|
-
</style>
|
180
|
-
</head>
|
181
|
-
<body>
|
182
|
-
<div id="header" >
|
183
|
-
<div id="logo">
|
184
|
-
<a href="index.html" title="Ruby on Rails"><img src="images/rails_logo_remix.gif" alt="Rails" height="140" width="110" /></a>
|
185
|
-
</div>
|
186
|
-
|
187
|
-
<h1 id="site_title"><span>Ruby on Rails</span></h1>
|
188
|
-
<h2 id="site_title_tagline">Sustainable productivity for web-application development</h2>
|
189
|
-
|
190
|
-
<ul id="navMain">
|
191
|
-
<li class="first-child"><a href="http://www.rubyonrails.org/" title="Ruby on Rails" class="ruby_on_rails">Ruby on Rails</a></li>
|
192
|
-
<li><a class="manuals" href="index.html" title="Manuals Index">Guides Index</a></li>
|
193
|
-
</ul>
|
194
|
-
</div>
|
195
|
-
|
196
|
-
<div id="container">
|
197
|
-
|
198
|
-
<div id="sidebar">
|
199
|
-
<h2>Chapters</h2>
|
200
|
-
<ol>
|
201
|
-
<li>
|
202
|
-
<a href="#_basic_caching">Basic Caching</a>
|
203
|
-
<ul>
|
204
|
-
|
205
|
-
<li><a href="#_page_caching">Page Caching</a></li>
|
206
|
-
|
207
|
-
<li><a href="#_action_caching">Action Caching</a></li>
|
208
|
-
|
209
|
-
<li><a href="#_fragment_caching">Fragment Caching</a></li>
|
210
|
-
|
211
|
-
<li><a href="#_sweepers">Sweepers</a></li>
|
212
|
-
|
213
|
-
<li><a href="#_sql_caching">SQL Caching</a></li>
|
214
|
-
|
215
|
-
<li><a href="#_cache_stores">Cache stores</a></li>
|
216
|
-
|
217
|
-
</ul>
|
218
|
-
</li>
|
219
|
-
<li>
|
220
|
-
<a href="#_advanced_caching">Advanced Caching</a>
|
221
|
-
</li>
|
222
|
-
</ol>
|
223
|
-
</div>
|
224
|
-
|
225
|
-
<div id="content">
|
226
|
-
<h1>Caching with Rails: An overview</h1>
|
227
|
-
<div id="preamble">
|
228
|
-
<div class="sectionbody">
|
229
|
-
<div class="para"><p>Everyone caches. This guide will teach you what you need to know about
|
230
|
-
avoiding that expensive round-trip to your database and returning what you
|
231
|
-
need to return to those hungry web clients in the shortest time possible.</p></div>
|
232
|
-
</div>
|
233
|
-
</div>
|
234
|
-
<h2 id="_basic_caching">1. Basic Caching</h2>
|
235
|
-
<div class="sectionbody">
|
236
|
-
<div class="para"><p>This is an introduction to the three types of caching techniques that Rails
|
237
|
-
provides by default without the use of any third party plugins.</p></div>
|
238
|
-
<div class="para"><p>To get started make sure config.action_controller.perform_caching is set
|
239
|
-
to true for your environment. This flag is normally set in the
|
240
|
-
corresponding config/environments/*.rb and caching is disabled by default
|
241
|
-
there for development and test, and enabled for production.</p></div>
|
242
|
-
<div class="listingblock">
|
243
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
244
|
-
by Lorenzo Bettini
|
245
|
-
http://www.lorenzobettini.it
|
246
|
-
http://www.gnu.org/software/src-highlite -->
|
247
|
-
<pre><tt>config<span style="color: #990000">.</span>action_controller<span style="color: #990000">.</span>perform_caching <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span>
|
248
|
-
</tt></pre></div></div>
|
249
|
-
<h3 id="_page_caching">1.1. Page Caching</h3>
|
250
|
-
<div class="para"><p>Page caching is a Rails mechanism which allows the request for a generated
|
251
|
-
page to be fulfilled by the webserver, without ever having to go through the
|
252
|
-
Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be
|
253
|
-
applied to every situation (such as pages that need authentication) and since
|
254
|
-
the webserver is literally just serving a file from the filesystem, cache
|
255
|
-
expiration is an issue that needs to be dealt with.</p></div>
|
256
|
-
<div class="para"><p>So, how do you enable this super-fast cache behavior? Simple, let's say you
|
257
|
-
have a controller called ProductsController and a <em>list</em> action that lists all
|
258
|
-
the products</p></div>
|
259
|
-
<div class="listingblock">
|
260
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
261
|
-
by Lorenzo Bettini
|
262
|
-
http://www.lorenzobettini.it
|
263
|
-
http://www.gnu.org/software/src-highlite -->
|
264
|
-
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> ProductsController <span style="color: #990000"><</span> ActionController
|
265
|
-
|
266
|
-
caches_page <span style="color: #990000">:</span>index
|
267
|
-
|
268
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> index<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
269
|
-
|
270
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
271
|
-
</tt></pre></div></div>
|
272
|
-
<div class="para"><p>The first time anyone requests products/index, Rails will generate a file
|
273
|
-
called index.html and the webserver will then look for that file before it
|
274
|
-
passes the next request for products/index to your Rails application.</p></div>
|
275
|
-
<div class="para"><p>By default, the page cache directory is set to Rails.public_path (which is
|
276
|
-
usually set to RAILS_ROOT + "/public") and this can be configured by
|
277
|
-
changing the configuration setting ActionController::Base.page_cache_directory. Changing the
|
278
|
-
default from /public helps avoid naming conflicts, since you may want to
|
279
|
-
put other static html in /public, but changing this will require web
|
280
|
-
server reconfiguration to let the web server know where to serve the
|
281
|
-
cached files from.</p></div>
|
282
|
-
<div class="para"><p>The Page Caching mechanism will automatically add a .html exxtension to
|
283
|
-
requests for pages that do not have an extension to make it easy for the
|
284
|
-
webserver to find those pages and this can be configured by changing the
|
285
|
-
configuration setting ActionController::Base.page_cache_extension.</p></div>
|
286
|
-
<div class="para"><p>In order to expire this page when a new product is added we could extend our
|
287
|
-
example controler like this:</p></div>
|
288
|
-
<div class="listingblock">
|
289
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
290
|
-
by Lorenzo Bettini
|
291
|
-
http://www.lorenzobettini.it
|
292
|
-
http://www.gnu.org/software/src-highlite -->
|
293
|
-
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> ProductsController <span style="color: #990000"><</span> ActionController
|
294
|
-
|
295
|
-
caches_page <span style="color: #990000">:</span>list
|
296
|
-
|
297
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> list<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
298
|
-
|
299
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> create
|
300
|
-
expire_page <span style="color: #990000">:</span>action <span style="color: #990000">=></span> <span style="color: #990000">:</span>list
|
301
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
302
|
-
|
303
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
304
|
-
</tt></pre></div></div>
|
305
|
-
<div class="para"><p>If you want a more complicated expiration scheme, you can use cache sweepers
|
306
|
-
to expire cached objects when things change. This is covered in the section on Sweepers.</p></div>
|
307
|
-
<h3 id="_action_caching">1.2. Action Caching</h3>
|
308
|
-
<div class="para"><p>One of the issues with Page Caching is that you cannot use it for pages that
|
309
|
-
require to restrict access somehow. This is where Action Caching comes in.
|
310
|
-
Action Caching works like Page Caching except for the fact that the incoming
|
311
|
-
web request does go from the webserver to the Rails stack and Action Pack so
|
312
|
-
that before filters can be run on it before the cache is served, so that
|
313
|
-
authentication and other restrictions can be used while still serving the
|
314
|
-
result of the output from a cached copy.</p></div>
|
315
|
-
<div class="para"><p>Clearing the cache works in the exact same way as with Page Caching.</p></div>
|
316
|
-
<div class="para"><p>Let's say you only wanted authenticated users to edit or create a Product
|
317
|
-
object, but still cache those pages:</p></div>
|
318
|
-
<div class="listingblock">
|
319
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
320
|
-
by Lorenzo Bettini
|
321
|
-
http://www.lorenzobettini.it
|
322
|
-
http://www.gnu.org/software/src-highlite -->
|
323
|
-
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> ProductsController <span style="color: #990000"><</span> ActionController
|
324
|
-
|
325
|
-
before_filter <span style="color: #990000">:</span>authenticate<span style="color: #990000">,</span> <span style="color: #990000">:</span>only <span style="color: #990000">=></span> <span style="color: #990000">[</span> <span style="color: #990000">:</span>edit<span style="color: #990000">,</span> <span style="color: #990000">:</span>create <span style="color: #990000">]</span>
|
326
|
-
caches_page <span style="color: #990000">:</span>list
|
327
|
-
caches_action <span style="color: #990000">:</span>edit
|
328
|
-
|
329
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> list<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
330
|
-
|
331
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> create
|
332
|
-
expire_page <span style="color: #990000">:</span>action <span style="color: #990000">=></span> <span style="color: #990000">:</span>list
|
333
|
-
expire_action <span style="color: #990000">:</span>action <span style="color: #990000">=></span> <span style="color: #990000">:</span>edit
|
334
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
335
|
-
|
336
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> edit<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
337
|
-
|
338
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
339
|
-
</tt></pre></div></div>
|
340
|
-
<div class="para"><p>And you can also use :if (or :unless) to pass a Proc that specifies when the
|
341
|
-
action should be cached. Also, you can use :layout ⇒ false to cache without
|
342
|
-
layout so that dynamic information in the layout such as logged in user info
|
343
|
-
or the number of items in the cart can be left uncached. This feature is
|
344
|
-
available as of Rails 2.2.</p></div>
|
345
|
-
<div class="para"><p>[More: more examples? Walk-through of Action Caching from request to response?
|
346
|
-
Description of Rake tasks to clear cached files? Show example of
|
347
|
-
subdomain caching? Talk about :cache_path, :if and assing blocks/Procs
|
348
|
-
to expire_action?]</p></div>
|
349
|
-
<h3 id="_fragment_caching">1.3. Fragment Caching</h3>
|
350
|
-
<div class="para"><p>Life would be perfect if we could get away with caching the entire contents of
|
351
|
-
a page or action and serving it out to the world. Unfortunately, dynamic web
|
352
|
-
applications usually build pages with a variety of components not all of which
|
353
|
-
have the same caching characteristics. In order to address such a dynamically
|
354
|
-
created page where different parts of the page need to be cached and expired
|
355
|
-
differently Rails provides a mechanism called Fragment Caching.</p></div>
|
356
|
-
<div class="para"><p>Fragment Caching allows a fragment of view logic to be wrapped in a cache
|
357
|
-
block and served out of the cache store when the next request comes in.</p></div>
|
358
|
-
<div class="para"><p>As an example, if you wanted to show all the orders placed on your website
|
359
|
-
in real time and didn't want to cache that part of the page, but did want
|
360
|
-
to cache the part of the page which lists all products available, you
|
361
|
-
could use this piece of code:</p></div>
|
362
|
-
<div class="listingblock">
|
363
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
364
|
-
by Lorenzo Bettini
|
365
|
-
http://www.lorenzobettini.it
|
366
|
-
http://www.gnu.org/software/src-highlite -->
|
367
|
-
<pre><tt><span style="color: #FF0000"><% Order.find_recent.each do |o| %></span>
|
368
|
-
<span style="color: #FF0000"><%= o.buyer.name %></span> bought <span style="color: #FF0000"><% o.product.name %></span>
|
369
|
-
<span style="color: #FF0000"><% end %></span>
|
370
|
-
|
371
|
-
<span style="color: #FF0000"><% cache do %></span>
|
372
|
-
All available products<span style="color: #990000">:</span>
|
373
|
-
<span style="color: #FF0000"><% Product.find(:all).each do |p| %></span>
|
374
|
-
<span style="color: #FF0000"><%= link_to p.name, product_url(p) %></span>
|
375
|
-
<span style="color: #FF0000"><% end %></span>
|
376
|
-
<span style="color: #FF0000"><% end %></span>
|
377
|
-
</tt></pre></div></div>
|
378
|
-
<div class="para"><p>The cache block in our example will bind to the action that called it and is
|
379
|
-
written out to the same place as the Action Cache, which means that if you
|
380
|
-
want to cache multiple fragments per action, you should provide an action_suffix to the cache call:</p></div>
|
381
|
-
<div class="listingblock">
|
382
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
383
|
-
by Lorenzo Bettini
|
384
|
-
http://www.lorenzobettini.it
|
385
|
-
http://www.gnu.org/software/src-highlite -->
|
386
|
-
<pre><tt><span style="color: #FF0000"><% cache(:action =></span> <span style="color: #FF0000">'recent'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>action_suffix <span style="color: #990000">=></span> <span style="color: #FF0000">'all_products'</span><span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">%></span>
|
387
|
-
All available products<span style="color: #990000">:</span>
|
388
|
-
</tt></pre></div></div>
|
389
|
-
<div class="para"><p>and you can expire it using the expire_fragment method, like so:</p></div>
|
390
|
-
<div class="listingblock">
|
391
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
392
|
-
by Lorenzo Bettini
|
393
|
-
http://www.lorenzobettini.it
|
394
|
-
http://www.gnu.org/software/src-highlite -->
|
395
|
-
<pre><tt>expire_fragment<span style="color: #990000">(:</span>controller <span style="color: #990000">=></span> <span style="color: #FF0000">'producst'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>action <span style="color: #990000">=></span> <span style="color: #FF0000">'recent'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>action_suffix <span style="color: #990000">=></span> 'all_products<span style="color: #990000">)</span>
|
396
|
-
</tt></pre></div></div>
|
397
|
-
<h3 id="_sweepers">1.4. Sweepers</h3>
|
398
|
-
<div class="para"><p>Cache sweeping is a mechanism which allows you to get around having a ton of
|
399
|
-
expire_{page,action,fragment} calls in your code by moving all the work
|
400
|
-
required to expire cached content into a ActionController::Caching::Sweeper
|
401
|
-
class that is an Observer and looks for changes to an object via callbacks,
|
402
|
-
and when a change occurs it expires the caches associated with that object n
|
403
|
-
an around or after filter.</p></div>
|
404
|
-
<div class="para"><p>Continuing with our Product controller example, we could rewrite it with a
|
405
|
-
sweeper such as the following:</p></div>
|
406
|
-
<div class="listingblock">
|
407
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
408
|
-
by Lorenzo Bettini
|
409
|
-
http://www.lorenzobettini.it
|
410
|
-
http://www.gnu.org/software/src-highlite -->
|
411
|
-
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> StoreSweeper <span style="color: #990000"><</span> ActionController<span style="color: #990000">::</span>Caching<span style="color: #990000">::</span>Sweeper
|
412
|
-
observe Product <span style="font-style: italic"><span style="color: #9A1900"># This sweeper is going to keep an eye on the Post model</span></span>
|
413
|
-
|
414
|
-
<span style="font-style: italic"><span style="color: #9A1900"># If our sweeper detects that a Post was created call this</span></span>
|
415
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> after_create<span style="color: #990000">(</span>product<span style="color: #990000">)</span>
|
416
|
-
expire_cache_for<span style="color: #990000">(</span>product<span style="color: #990000">)</span>
|
417
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
418
|
-
|
419
|
-
<span style="font-style: italic"><span style="color: #9A1900"># If our sweeper detects that a Post was updated call this</span></span>
|
420
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> after_update<span style="color: #990000">(</span>product<span style="color: #990000">)</span>
|
421
|
-
expire_cache_for<span style="color: #990000">(</span>product<span style="color: #990000">)</span>
|
422
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
423
|
-
|
424
|
-
<span style="font-style: italic"><span style="color: #9A1900"># If our sweeper detects that a Post was deleted call this</span></span>
|
425
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> after_destroy<span style="color: #990000">(</span>product<span style="color: #990000">)</span>
|
426
|
-
expire_cache_for<span style="color: #990000">(</span>product<span style="color: #990000">)</span>
|
427
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
428
|
-
|
429
|
-
private
|
430
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> expire_cache_for<span style="color: #990000">(</span>record<span style="color: #990000">)</span>
|
431
|
-
<span style="font-style: italic"><span style="color: #9A1900"># Expire the list page now that we added a new product</span></span>
|
432
|
-
expire_page<span style="color: #990000">(:</span>controller <span style="color: #990000">=></span> <span style="color: #FF0000">'#{record}'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>action <span style="color: #990000">=></span> <span style="color: #FF0000">'list'</span><span style="color: #990000">)</span>
|
433
|
-
|
434
|
-
<span style="font-style: italic"><span style="color: #9A1900"># Expire a fragment</span></span>
|
435
|
-
expire_fragment<span style="color: #990000">(:</span>controller <span style="color: #990000">=></span> <span style="color: #FF0000">'#{record}'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>action <span style="color: #990000">=></span> <span style="color: #FF0000">'recent'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>action_suffix <span style="color: #990000">=></span> <span style="color: #FF0000">'all_products'</span><span style="color: #990000">)</span>
|
436
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
437
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
438
|
-
</tt></pre></div></div>
|
439
|
-
<div class="para"><p>Then we add it to our controller to tell it to call the sweeper when certain
|
440
|
-
actions are called. So, if we wanted to expire the cached content for the
|
441
|
-
list and edit actions when the create action was called, we could do the
|
442
|
-
following:</p></div>
|
443
|
-
<div class="listingblock">
|
444
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
445
|
-
by Lorenzo Bettini
|
446
|
-
http://www.lorenzobettini.it
|
447
|
-
http://www.gnu.org/software/src-highlite -->
|
448
|
-
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> ProductsController <span style="color: #990000"><</span> ActionController
|
449
|
-
|
450
|
-
before_filter <span style="color: #990000">:</span>authenticate<span style="color: #990000">,</span> <span style="color: #990000">:</span>only <span style="color: #990000">=></span> <span style="color: #990000">[</span> <span style="color: #990000">:</span>edit<span style="color: #990000">,</span> <span style="color: #990000">:</span>create <span style="color: #990000">]</span>
|
451
|
-
caches_page <span style="color: #990000">:</span>list
|
452
|
-
caches_action <span style="color: #990000">:</span>edit
|
453
|
-
cache_sweeper <span style="color: #990000">:</span>store_sweeper<span style="color: #990000">,</span> <span style="color: #990000">:</span>only <span style="color: #990000">=></span> <span style="color: #990000">[</span> <span style="color: #990000">:</span>create <span style="color: #990000">]</span>
|
454
|
-
|
455
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> list<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
456
|
-
|
457
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> create
|
458
|
-
expire_page <span style="color: #990000">:</span>action <span style="color: #990000">=></span> <span style="color: #990000">:</span>list
|
459
|
-
expire_action <span style="color: #990000">:</span>action <span style="color: #990000">=></span> <span style="color: #990000">:</span>edit
|
460
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
461
|
-
|
462
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> edit<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
463
|
-
|
464
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
465
|
-
</tt></pre></div></div>
|
466
|
-
<h3 id="_sql_caching">1.5. SQL Caching</h3>
|
467
|
-
<div class="para"><p>Query caching is a Rails feature that caches the result set returned by each
|
468
|
-
query so that if Rails encounters the same query again for that request, it
|
469
|
-
will used the cached result set as opposed to running the query against the
|
470
|
-
database again.</p></div>
|
471
|
-
<div class="para"><p>For example:</p></div>
|
472
|
-
<div class="listingblock">
|
473
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
474
|
-
by Lorenzo Bettini
|
475
|
-
http://www.lorenzobettini.it
|
476
|
-
http://www.gnu.org/software/src-highlite -->
|
477
|
-
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> ProductsController <span style="color: #990000"><</span> ActionController
|
478
|
-
|
479
|
-
before_filter <span style="color: #990000">:</span>authenticate<span style="color: #990000">,</span> <span style="color: #990000">:</span>only <span style="color: #990000">=></span> <span style="color: #990000">[</span> <span style="color: #990000">:</span>edit<span style="color: #990000">,</span> <span style="color: #990000">:</span>create <span style="color: #990000">]</span>
|
480
|
-
caches_page <span style="color: #990000">:</span>list
|
481
|
-
caches_action <span style="color: #990000">:</span>edit
|
482
|
-
cache_sweeper <span style="color: #990000">:</span>store_sweeper<span style="color: #990000">,</span> <span style="color: #990000">:</span>only <span style="color: #990000">=></span> <span style="color: #990000">[</span> <span style="color: #990000">:</span>create <span style="color: #990000">]</span>
|
483
|
-
|
484
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> list
|
485
|
-
<span style="font-style: italic"><span style="color: #9A1900"># Run a find query</span></span>
|
486
|
-
Product<span style="color: #990000">.</span>find<span style="color: #990000">(:</span>all<span style="color: #990000">)</span>
|
487
|
-
|
488
|
-
<span style="color: #990000">...</span>
|
489
|
-
|
490
|
-
<span style="font-style: italic"><span style="color: #9A1900"># Run the same query again</span></span>
|
491
|
-
Product<span style="color: #990000">.</span>find<span style="color: #990000">(:</span>all<span style="color: #990000">)</span>
|
492
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
493
|
-
|
494
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> create
|
495
|
-
expire_page <span style="color: #990000">:</span>action <span style="color: #990000">=></span> <span style="color: #990000">:</span>list
|
496
|
-
expire_action <span style="color: #990000">:</span>action <span style="color: #990000">=></span> <span style="color: #990000">:</span>edit
|
497
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
498
|
-
|
499
|
-
<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> edit<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
500
|
-
|
501
|
-
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
502
|
-
</tt></pre></div></div>
|
503
|
-
<div class="para"><p>In the <em>list</em> action above, the result set returned by the first
|
504
|
-
Product.find(:all) will be cached and will be used to avoid querying the
|
505
|
-
database again the second time that finder is called.</p></div>
|
506
|
-
<div class="para"><p>Query caches are created at the start of an action and destroyed at the end of
|
507
|
-
that action and thus persist only for the duration of the action.</p></div>
|
508
|
-
<h3 id="_cache_stores">1.6. Cache stores</h3>
|
509
|
-
<div class="para"><p>Rails provides different stores for the cached data for action and fragment
|
510
|
-
caches. Page caches are always stored on disk.</p></div>
|
511
|
-
<div class="para"><p>The cache stores provided include:</p></div>
|
512
|
-
<div class="para"><p>1) Memory store: Cached data is stored in the memory allocated to the Rails
|
513
|
-
process, which is fine for WEBrick and for FCGI (if you
|
514
|
-
don't care that each FCGI process holds its own fragment
|
515
|
-
store). It's not suitable for CGI as the process is thrown
|
516
|
-
away at the end of each request. It can potentially also
|
517
|
-
take up a lot of memory since each process keeps all the
|
518
|
-
caches in memory.</p></div>
|
519
|
-
<div class="listingblock">
|
520
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
521
|
-
by Lorenzo Bettini
|
522
|
-
http://www.lorenzobettini.it
|
523
|
-
http://www.gnu.org/software/src-highlite -->
|
524
|
-
<pre><tt>ActionController<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>cache_store <span style="color: #990000">=</span> <span style="color: #990000">:</span>memory_store
|
525
|
-
</tt></pre></div></div>
|
526
|
-
<div class="para"><p>2) File store: Cached data is stored on the disk, this is the default store
|
527
|
-
and the default path for this store is: /tmp/cache. Works
|
528
|
-
well for all types of environments and allows all processes
|
529
|
-
running from the same application directory to access the
|
530
|
-
cached content.</p></div>
|
531
|
-
<div class="listingblock">
|
532
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
533
|
-
by Lorenzo Bettini
|
534
|
-
http://www.lorenzobettini.it
|
535
|
-
http://www.gnu.org/software/src-highlite -->
|
536
|
-
<pre><tt>ActionController<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>cache_store <span style="color: #990000">=</span> <span style="color: #990000">:</span>file_store<span style="color: #990000">,</span> <span style="color: #FF0000">"/path/to/cache/directory"</span>
|
537
|
-
</tt></pre></div></div>
|
538
|
-
<div class="para"><p>3) DRb store: Cached data is stored in a separate shared DRb process that all
|
539
|
-
servers communicate with. This works for all environments and
|
540
|
-
only keeps one cache around for all processes, but requires
|
541
|
-
that you run and manage a separate DRb process.</p></div>
|
542
|
-
<div class="listingblock">
|
543
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
544
|
-
by Lorenzo Bettini
|
545
|
-
http://www.lorenzobettini.it
|
546
|
-
http://www.gnu.org/software/src-highlite -->
|
547
|
-
<pre><tt>ActionController<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>cache_store <span style="color: #990000">=</span> <span style="color: #990000">:</span>drb_store<span style="color: #990000">,</span> <span style="color: #FF0000">"druby://localhost:9192"</span>
|
548
|
-
</tt></pre></div></div>
|
549
|
-
<div class="para"><p>4) MemCached store: Works like DRbStore, but uses Danga's MemCache instead.
|
550
|
-
Requires the ruby-memcache library:
|
551
|
-
gem install ruby-memcache.</p></div>
|
552
|
-
<div class="listingblock">
|
553
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
554
|
-
by Lorenzo Bettini
|
555
|
-
http://www.lorenzobettini.it
|
556
|
-
http://www.gnu.org/software/src-highlite -->
|
557
|
-
<pre><tt>ActionController<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>cache_store <span style="color: #990000">=</span> <span style="color: #990000">:</span>mem_cache_store<span style="color: #990000">,</span> <span style="color: #FF0000">"localhost"</span>
|
558
|
-
</tt></pre></div></div>
|
559
|
-
<div class="para"><p>5) Custom store: You can define your own cache store (new in Rails 2.1)</p></div>
|
560
|
-
<div class="listingblock">
|
561
|
-
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
562
|
-
by Lorenzo Bettini
|
563
|
-
http://www.lorenzobettini.it
|
564
|
-
http://www.gnu.org/software/src-highlite -->
|
565
|
-
<pre><tt>ActionController<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>cache_store <span style="color: #990000">=</span> MyOwnStore<span style="color: #990000">.</span>new<span style="color: #990000">(</span><span style="color: #FF0000">"parameter"</span><span style="color: #990000">)</span>
|
566
|
-
</tt></pre></div></div>
|
567
|
-
</div>
|
568
|
-
<h2 id="_advanced_caching">2. Advanced Caching</h2>
|
569
|
-
<div class="sectionbody">
|
570
|
-
<div class="para"><p>Along with the built-in mechanisms outlined above, a number of excellent
|
571
|
-
plugins exist to help with finer grained control over caching. These include
|
572
|
-
Chris Wanstrath's excellent cache_fu plugin (more info here:
|
573
|
-
<a href="http://errtheblog.com/posts/57-kickin-ass-w-cachefu">http://errtheblog.com/posts/57-kickin-ass-w-cachefu</a>) and Evan Weaver's
|
574
|
-
interlock plugin (more info here:
|
575
|
-
<a href="http://blog.evanweaver.com/articles/2007/12/13/better-rails-caching/">http://blog.evanweaver.com/articles/2007/12/13/better-rails-caching/</a>). Both
|
576
|
-
of these plugins play nice with memcached and are a must-see for anyone
|
577
|
-
seriously considering optimizing their caching needs.</p></div>
|
578
|
-
</div>
|
579
|
-
|
580
|
-
</div>
|
581
|
-
</div>
|
582
|
-
</body>
|
583
|
-
</html>
|