actionpack-page_caching 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack-page_caching might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcc463b295ac09cfa6b0ca15557d7e00da2bf92b
4
- data.tar.gz: 1ca39e53842cb9446214249e47cfe791596e763e
3
+ metadata.gz: 4a8baf2e26a08aa06aabc67d4783382223dbef4c
4
+ data.tar.gz: '081b862c7762f68baa7ca15a9358689773616bb0'
5
5
  SHA512:
6
- metadata.gz: cd19ec3f9214460795607de16e4d66769b7621cac4caa329ada8ec810b9414a6f1e5280b8132d683adcba70343b85750356c8d0d3d017f7d98ed199384ad1b14
7
- data.tar.gz: afa5b80f7c9ce7c54e284fa35bc3c484d7c0552aff051999dd668edd99827059570b019a01e00da544d23c68a78e9427354f68e5b36981221fc808f38f283912
6
+ metadata.gz: 62aca2629984d4538f10ed0cad44265e91238f231cdd071fb36875a35e6607f547ab69aa33cf7e45c87b05677db69f777682cd2324de6c4a3de133e922fe8aa6
7
+ data.tar.gz: 7b354f5a3fc117733b5f92228bae747730dda7c70293aa60e7ea8e337c449897f5fa3e2a36179f8b8b409ebd5ff40ee360ba9a7ffb147bd46c71e2431089a15f
@@ -1,3 +1,14 @@
1
+ ## 1.1.1 (September 25, 2018)
2
+
3
+ * Fixes handling of several forward slashes as root path.
4
+
5
+ *Xavier Noria*
6
+
7
+ * Documentation overhaul.
8
+
9
+ *Xavier Noria*
10
+
11
+
1
12
  ## 1.1.0 (January 23, 2017)
2
13
 
3
14
  * Support dynamic `page_cache_directory` using a Proc, Symbol or callable
data/README.md CHANGED
@@ -1,12 +1,41 @@
1
- actionpack-page_caching
2
- =======================
1
+ # actionpack-page_caching
3
2
 
4
3
  Static page caching for Action Pack (removed from core in Rails 4.0).
5
4
 
6
- Installation
7
- ------------
5
+ ## Introduction
6
+
7
+ Page caching is an approach to caching in which response bodies are stored in
8
+ files that the web server can serve directly:
9
+
10
+ 1. A request to endpoint _E_ arrives.
11
+ 2. Its response is calculated and stored in a file _F_.
12
+ 3. Next time _E_ is requested, the web server sends _F_ directly.
13
+
14
+ That applies only to GET or HEAD requests whose reponse code is 200, the rest
15
+ are ignored.
16
+
17
+ Unlike caching proxies or other more sophisticated setups, page caching results
18
+ in a dramatic speed up while being dead simple at the same time. Awesome
19
+ cost/benefit.
20
+
21
+ The reason for such performance boost is that cached endpoints are
22
+ short-circuited by the web server, which is very efficient at serving static
23
+ files. Requests to cached endpoints do not even reach your Rails application.
8
24
 
9
- Add this line to your application's Gemfile:
25
+ This technique, however, is only suitable for pages that do not need to go
26
+ through your Rails stack, precisely. For example, content management systems
27
+ like wikis have typically many pages that are a great fit for this approach, but
28
+ account-based systems where people log in and manipulate their own data are
29
+ often less likely candidates. As a use case you can check, [Rails
30
+ Contributors](https://contributors.rubyonrails.org/) makes heavy use of page
31
+ caching. Its source code is [here](https://github.com/rails/rails-contributors).
32
+
33
+ It is not all or nothing, though, in HTML cached pages JavaScript can still
34
+ tweak details here and there dynamically as a trade-off.
35
+
36
+ ## Installation
37
+
38
+ Add this line to your application's `Gemfile`:
10
39
 
11
40
  ``` ruby
12
41
  gem "actionpack-page_caching"
@@ -14,39 +43,71 @@ gem "actionpack-page_caching"
14
43
 
15
44
  And then execute:
16
45
 
17
- $ bundle
46
+ ```
47
+ $ bundle
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ### Enable Caching
53
+
54
+ Page caching needs caching enabled:
55
+
56
+ ```ruby
57
+ config.action_controller.perform_caching = true
58
+ ```
59
+
60
+ That goes typically in `config/environments/production.rb`, but you can activate
61
+ that flag in any mode.
62
+
63
+ Since Rails 5 there is a special toggler to easily enable/disable caching in
64
+ `development` mode without editing its configuration file. Just execute
65
+
66
+ ```
67
+ $ bin/rails dev:cache
68
+ ```
69
+
70
+ to enable/disable caching in `development` mode.
71
+
72
+ ### Configure the Cache Directory
18
73
 
19
- Or install it yourself as:
74
+ #### Default Cache Directory
20
75
 
21
- $ gem install actionpack-page_caching
76
+ By default, files are stored below the `public` directory of your Rails
77
+ application, with a path that matches the one in the URL.
22
78
 
23
- Usage
24
- -----
79
+ For example, a page-cached request to `/posts/what-is-new-in-rails-6` would be
80
+ stored by default in the file `public/posts/what-is-new-in-rails-6.html`, and
81
+ the web server would be configured to check that path in the file system before
82
+ falling back to Rails. More on this later.
25
83
 
26
- Page caching is an approach to caching where the entire action output is
27
- stored as a HTML file that the web server can serve without going through
28
- Action Pack. This is the fastest way to cache your content as opposed to going
29
- dynamically through the process of generating the content. Unfortunately, this
30
- incredible speed-up is only available to stateless pages where all visitors are
31
- treated the same. Content management systems -- including weblogs and wikis --
32
- have many pages that are a great fit for this approach, but account-based systems
33
- where people log in and manipulate their own data are often less likely candidates.
84
+ #### Custom Cache Directory
34
85
 
35
- First you need to set `page_cache_directory` in your configuration file:
86
+ The default page caching directory can be overridden:
36
87
 
37
88
  ``` ruby
38
- config.action_controller.page_cache_directory = "#{Rails.root}/public/cached_pages"
89
+ config.action_controller.page_cache_directory = Rails.root.join("public", "cached_pages")
39
90
  ```
40
91
 
41
- The `page_cache_directory` setting can be used with a Proc:
92
+ There is no need to ensure the directory exists when the application boots,
93
+ whenever a page has to be cached, the page cache directory is created if needed.
94
+
95
+ #### Custom Cache Directory per Controller
96
+
97
+ The globally configured cache directory, default or custom, can be overridden in
98
+ each controller. There are three ways of doing this.
99
+
100
+ With a lambda:
42
101
 
43
102
  ``` ruby
44
103
  class WeblogController < ApplicationController
45
- self.page_cache_directory = -> { Rails.root.join("public", request.domain) }
104
+ self.page_cache_directory = -> {
105
+ Rails.root.join("public", request.domain)
106
+ }
46
107
  end
47
108
  ```
48
109
 
49
- a Symbol:
110
+ a symbol:
50
111
 
51
112
  ``` ruby
52
113
  class WeblogController < ApplicationController
@@ -73,7 +134,11 @@ class WeblogController < ApplicationController
73
134
  end
74
135
  ```
75
136
 
76
- Specifying which actions to cache is done through the `caches_page` class method:
137
+ Intermediate directories are created as needed also in this case.
138
+
139
+ ### Specify Actions to be Cached
140
+
141
+ Specifying which actions have to be cached is done through the `caches_page` class method:
77
142
 
78
143
  ``` ruby
79
144
  class WeblogController < ActionController::Base
@@ -81,17 +146,44 @@ class WeblogController < ActionController::Base
81
146
  end
82
147
  ```
83
148
 
84
- This will generate cache files such as `weblog/show/5.html` and
85
- `weblog/new.html`, which match the URLs used that would normally trigger
86
- dynamic page generation. Page caching works by configuring a web server to first
87
- check for the existence of files on disk, and to serve them directly when found,
88
- without passing the request through to Action Pack. This is much faster than
89
- handling the full dynamic request in the usual way.
149
+ ### Configure The Web Server
150
+
151
+ The [wiki](https://github.com/rails/actionpack-page_caching/wiki) of the project
152
+ has some examples of web server configuration.
153
+
154
+ ### Cache Expiration
155
+
156
+ Expiration of the cache is handled by deleting the cached files, which results
157
+ in a lazy regeneration approach in which the content is stored again as cached
158
+ endpoints are hit.
90
159
 
91
- Expiration of the cache is handled by deleting the cached file, which results
92
- in a lazy regeneration approach where the cache is not restored before another
93
- hit is made against it. The API for doing so mimics the options from `url_for`
94
- and friends:
160
+ #### Full Cache Expiration
161
+
162
+ If the cache is stored in a separate directory like `public/cached_pages`, you
163
+ can easily expire the whole thing by removing said directory.
164
+
165
+ Removing a directory recursively with something like `rm -rf` is unreliable
166
+ because that operation is not atomic and can mess up with concurrent page cache
167
+ generation.
168
+
169
+ In POSIX systems moving a file is atomic, so the recommended approach would be
170
+ to move the directory first out of the way, and then recursively delete that
171
+ one. Something like
172
+
173
+ ```bash
174
+ #!/bin/bash
175
+
176
+ tmp=public/cached_pages-$(date +%s)
177
+ mv public/cached_pages $tmp
178
+ rm -rf $tmp
179
+ ```
180
+
181
+ As noted before, the page cache directory is created if it does not exist, so
182
+ moving the directory is enough to have a clean cache, no need to recreate.
183
+
184
+ #### Fine-grained Cache Expiration
185
+
186
+ The API for doing so mimics the options from `url_for` and friends:
95
187
 
96
188
  ``` ruby
97
189
  class WeblogController < ActionController::Base
@@ -103,12 +195,10 @@ class WeblogController < ActionController::Base
103
195
  end
104
196
  ```
105
197
 
106
- Additionally, you can expire caches using [Sweepers](https://github.com/rails/rails-observers#action-controller-sweeper)
107
- that act on changes in the model to determine when a cache is supposed to be expired.
108
-
109
- Finally, configure your web server to serve these static pages when they are present
110
- rather than the original files. See the [project wiki][1] for example configurations.
111
- [1]: https://github.com/rails/actionpack-page_caching/wiki
198
+ Additionally, you can expire caches using
199
+ [Sweepers](https://github.com/rails/rails-observers#action-controller-sweeper)
200
+ that act on changes in the model to determine when a cache is supposed to be
201
+ expired.
112
202
 
113
203
  Contributing
114
204
  ------------
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "actionpack-page_caching"
3
- gem.version = "1.1.0"
3
+ gem.version = "1.1.1"
4
4
  gem.author = "David Heinemeier Hansson"
5
5
  gem.email = "david@loudthinking.com"
6
6
  gem.description = "Static page caching for Action Pack (removed from core in Rails 4.0)"
@@ -141,7 +141,7 @@ module ActionController
141
141
  end
142
142
 
143
143
  def cache_file(path, extension)
144
- if path.empty? || path == "/"
144
+ if path.empty? || path =~ %r{\A/+\z}
145
145
  name = "/index"
146
146
  else
147
147
  name = URI.parser.unescape(path.chomp("/"))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionpack-page_caching
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-23 00:00:00.000000000 Z
11
+ date: 2018-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.6.8
95
+ rubygems_version: 2.6.11
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Static page caching for Action Pack (removed from core in Rails 4.0)