actionpack-action_caching 1.0.0 → 1.2.2
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.
- checksums.yaml +7 -0
- data/.codeclimate.yml +7 -0
- data/.github/workflows/ci.yml +77 -0
- data/.gitignore +3 -15
- data/.rubocop.yml +116 -0
- data/CHANGELOG.md +81 -0
- data/Gemfile +2 -2
- data/README.md +54 -35
- data/Rakefile +5 -5
- data/actionpack-action_caching.gemspec +21 -14
- data/gemfiles/Gemfile-4-2-stable +10 -0
- data/gemfiles/Gemfile-5-0-stable +5 -0
- data/gemfiles/Gemfile-5-1-stable +5 -0
- data/gemfiles/Gemfile-5-2-stable +5 -0
- data/gemfiles/Gemfile-6-0-stable +5 -0
- data/gemfiles/Gemfile-6-1-stable +5 -0
- data/gemfiles/Gemfile-edge +6 -0
- data/lib/action_controller/action_caching.rb +6 -0
- data/lib/action_controller/caching/actions.rb +68 -22
- data/lib/actionpack/action_caching.rb +1 -1
- data/lib/actionpack/action_caching/railtie.rb +13 -0
- data/test/abstract_unit.rb +8 -37
- data/test/caching_test.rb +533 -126
- data/test/fixtures/layouts/talk_from_action.html.erb +2 -0
- metadata +42 -48
- data/.travis.yml +0 -17
- data/test/fixtures/layouts/talk_from_action.erb +0 -2
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d5a35e289d60b7b914b0b671d816c17e0abcdf42a97e6b8be14a255e230858c8
|
4
|
+
data.tar.gz: 4fe16b31cfac741be48dedc405659ef387b18c0f2199817f4b8b0987da5e1e5e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0ac9a52dd25c03562d88acd255c1c1ae69d21753da1498858c1ef6d56c0937ed206a73238bd86cac92fe8b88afdddf991a35450a60a7402246e131af625287ba
|
7
|
+
data.tar.gz: e11f0ccd152d9ff6e9a0f3411e3099f5dde36b9bf7cbad4bf2711e9801e673d2d21f532a816054b53722a716526752d0f1c42b4c90eddb139b1fddad7967a5df
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- 'master'
|
7
|
+
pull_request:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
gemfile:
|
14
|
+
- '4-2-stable'
|
15
|
+
- '5-0-stable'
|
16
|
+
- '5-1-stable'
|
17
|
+
- '5-2-stable'
|
18
|
+
- '6-0-stable'
|
19
|
+
- '6-1-stable'
|
20
|
+
- 'edge'
|
21
|
+
ruby:
|
22
|
+
- '2.4'
|
23
|
+
- '2.5'
|
24
|
+
- '2.6'
|
25
|
+
- '2.7'
|
26
|
+
- '3.0'
|
27
|
+
exclude:
|
28
|
+
- gemfile: '4-2-stable'
|
29
|
+
ruby: '2.5'
|
30
|
+
- gemfile: '4-2-stable'
|
31
|
+
ruby: '2.6'
|
32
|
+
- gemfile: '4-2-stable'
|
33
|
+
ruby: '2.7'
|
34
|
+
- gemfile: '4-2-stable'
|
35
|
+
ruby: '3.0'
|
36
|
+
- gemfile: '5-0-stable'
|
37
|
+
ruby: '2.7'
|
38
|
+
- gemfile: '5-0-stable'
|
39
|
+
ruby: '3.0'
|
40
|
+
- gemfile: '5-1-stable'
|
41
|
+
ruby: '2.7'
|
42
|
+
- gemfile: '5-1-stable'
|
43
|
+
ruby: '3.0'
|
44
|
+
- gemfile: '5-2-stable'
|
45
|
+
ruby: '2.7'
|
46
|
+
- gemfile: '5-2-stable'
|
47
|
+
ruby: '3.0'
|
48
|
+
- gemfile: '6-0-stable'
|
49
|
+
ruby: '2.4'
|
50
|
+
- gemfile: '6-1-stable'
|
51
|
+
ruby: '2.4'
|
52
|
+
- gemfile: 'edge'
|
53
|
+
ruby: '2.4'
|
54
|
+
- gemfile: 'edge'
|
55
|
+
ruby: '2.5'
|
56
|
+
- gemfile: 'edge'
|
57
|
+
ruby: '2.6'
|
58
|
+
fail-fast: false
|
59
|
+
|
60
|
+
runs-on: ubuntu-latest
|
61
|
+
name: ${{ matrix.ruby }} rails-${{ matrix.gemfile }}
|
62
|
+
|
63
|
+
steps:
|
64
|
+
- uses: actions/checkout@v2
|
65
|
+
|
66
|
+
- uses: ruby/setup-ruby@v1
|
67
|
+
with:
|
68
|
+
ruby-version: ${{ matrix.ruby }}
|
69
|
+
bundler-cache: true
|
70
|
+
bundler: ${{ fromJSON('["2", "1"]')[matrix.ruby == '2.4'] }}
|
71
|
+
|
72
|
+
- run: bundle exec rake test
|
73
|
+
|
74
|
+
env:
|
75
|
+
BUNDLE_GEMFILE: gemfiles/Gemfile-${{ matrix.gemfile }}
|
76
|
+
BUNDLE_JOBS: 4
|
77
|
+
BUNDLE_RETRY: 3
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
|
4
|
+
# to ignore them, so only the ones explicitly set in this file are enabled.
|
5
|
+
DisabledByDefault: true
|
6
|
+
|
7
|
+
# Prefer &&/|| over and/or.
|
8
|
+
Style/AndOr:
|
9
|
+
Enabled: true
|
10
|
+
|
11
|
+
# Do not use braces for hash literals when they are the last argument of a
|
12
|
+
# method call.
|
13
|
+
Style/BracesAroundHashParameters:
|
14
|
+
Enabled: true
|
15
|
+
|
16
|
+
# Align `when` with `case`.
|
17
|
+
Style/CaseIndentation:
|
18
|
+
Enabled: true
|
19
|
+
|
20
|
+
# Align comments with method definitions.
|
21
|
+
Style/CommentIndentation:
|
22
|
+
Enabled: true
|
23
|
+
|
24
|
+
# No extra empty lines.
|
25
|
+
Style/EmptyLines:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
# In a regular class definition, no empty lines around the body.
|
29
|
+
Style/EmptyLinesAroundClassBody:
|
30
|
+
Enabled: true
|
31
|
+
|
32
|
+
# In a regular module definition, no empty lines around the body.
|
33
|
+
Style/EmptyLinesAroundModuleBody:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
37
|
+
Style/HashSyntax:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
# Method definitions after `private` or `protected` isolated calls need one
|
41
|
+
# extra level of indentation.
|
42
|
+
Style/IndentationConsistency:
|
43
|
+
Enabled: true
|
44
|
+
EnforcedStyle: rails
|
45
|
+
|
46
|
+
# Two spaces, no tabs (for indentation).
|
47
|
+
Style/IndentationWidth:
|
48
|
+
Enabled: true
|
49
|
+
|
50
|
+
Style/SpaceAfterColon:
|
51
|
+
Enabled: true
|
52
|
+
|
53
|
+
Style/SpaceAfterComma:
|
54
|
+
Enabled: true
|
55
|
+
|
56
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
57
|
+
Enabled: true
|
58
|
+
|
59
|
+
Style/SpaceAroundKeyword:
|
60
|
+
Enabled: true
|
61
|
+
|
62
|
+
Style/SpaceAroundOperators:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
Style/SpaceBeforeFirstArg:
|
66
|
+
Enabled: true
|
67
|
+
|
68
|
+
# Defining a method with parameters needs parentheses.
|
69
|
+
Style/MethodDefParentheses:
|
70
|
+
Enabled: true
|
71
|
+
|
72
|
+
# Use `foo {}` not `foo{}`.
|
73
|
+
Style/SpaceBeforeBlockBraces:
|
74
|
+
Enabled: true
|
75
|
+
|
76
|
+
# Use `foo { bar }` not `foo {bar}`.
|
77
|
+
Style/SpaceInsideBlockBraces:
|
78
|
+
Enabled: true
|
79
|
+
|
80
|
+
# Use `{ a: 1 }` not `{a:1}`.
|
81
|
+
Style/SpaceInsideHashLiteralBraces:
|
82
|
+
Enabled: true
|
83
|
+
|
84
|
+
Style/SpaceInsideParens:
|
85
|
+
Enabled: true
|
86
|
+
|
87
|
+
# Check quotes usage according to lint rule below.
|
88
|
+
Style/StringLiterals:
|
89
|
+
Enabled: true
|
90
|
+
EnforcedStyle: double_quotes
|
91
|
+
|
92
|
+
# Detect hard tabs, no hard tabs.
|
93
|
+
Style/Tab:
|
94
|
+
Enabled: true
|
95
|
+
|
96
|
+
# Blank lines should not have any spaces.
|
97
|
+
Style/TrailingBlankLines:
|
98
|
+
Enabled: true
|
99
|
+
|
100
|
+
# No trailing whitespace.
|
101
|
+
Style/TrailingWhitespace:
|
102
|
+
Enabled: true
|
103
|
+
|
104
|
+
# Use quotes for string literals when they are enough.
|
105
|
+
Style/UnneededPercentQ:
|
106
|
+
Enabled: true
|
107
|
+
|
108
|
+
# Align `end` with the matching keyword or starting expression except for
|
109
|
+
# assignments, where it should be aligned with the LHS.
|
110
|
+
Lint/EndAlignment:
|
111
|
+
Enabled: true
|
112
|
+
AlignWith: variable
|
113
|
+
|
114
|
+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
115
|
+
Lint/RequireParentheses:
|
116
|
+
Enabled: true
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
## 1.2.2 (May 10, 2021)
|
2
|
+
|
3
|
+
* Add support for Rails 6.1
|
4
|
+
|
5
|
+
*Jonathan Fleckenstein*, *Prem Sichanugrist*
|
6
|
+
|
7
|
+
|
8
|
+
## 1.2.1 (November 12, 2019)
|
9
|
+
|
10
|
+
* Fix HTML escaping when `:layout` is `false`.
|
11
|
+
|
12
|
+
*Anton Katunin*
|
13
|
+
|
14
|
+
* Add support to Rails 6.
|
15
|
+
|
16
|
+
*Jacob Bednarz*
|
17
|
+
|
18
|
+
|
19
|
+
## 1.2.0 (January 23, 2017)
|
20
|
+
|
21
|
+
* Support proc options with zero arguments
|
22
|
+
|
23
|
+
Fixes #40.
|
24
|
+
|
25
|
+
*Andrew White*
|
26
|
+
|
27
|
+
* The options `:layout` and `:cache_path` now behave the same when
|
28
|
+
passed a `Symbol`, `Proc` or object that responds to call.
|
29
|
+
|
30
|
+
*Andrew White*
|
31
|
+
|
32
|
+
* Respect `Accept` header when caching actions
|
33
|
+
|
34
|
+
Fixes #18.
|
35
|
+
|
36
|
+
*Andrew White*
|
37
|
+
|
38
|
+
* Support Rails 4.0, 4.1, 4.2, 5.0 and edge
|
39
|
+
|
40
|
+
*Eileen Uchitelle*, *Andrew White*
|
41
|
+
|
42
|
+
* Call `to_s` on the extension as it may be a symbol
|
43
|
+
|
44
|
+
Fixes #10.
|
45
|
+
|
46
|
+
*Andrew White*
|
47
|
+
|
48
|
+
|
49
|
+
## 1.1.1 (January 2, 2014)
|
50
|
+
|
51
|
+
* Fix load order problem with other gems
|
52
|
+
|
53
|
+
*Andrew White*
|
54
|
+
|
55
|
+
|
56
|
+
## 1.1.0 (November 1, 2013)
|
57
|
+
|
58
|
+
* Allow to use non-proc object in `cache_path` option. You can pass an object that
|
59
|
+
responds to a `call` method.
|
60
|
+
|
61
|
+
Example:
|
62
|
+
|
63
|
+
class CachePath
|
64
|
+
def call(controller)
|
65
|
+
controller.id
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class TestController < ApplicationController
|
70
|
+
caches_action :index, :cache_path => CachePath.new
|
71
|
+
def index; end
|
72
|
+
end
|
73
|
+
|
74
|
+
*Piotr Niełacny*
|
75
|
+
|
76
|
+
|
77
|
+
## 1.0.0 (February 28, 2013)
|
78
|
+
|
79
|
+
* Extract Action Pack - Action Caching from Rails core.
|
80
|
+
|
81
|
+
*Francesco Rodriguez*
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
actionpack-action_caching
|
2
2
|
=========================
|
3
3
|
|
4
|
-
Action caching for Action Pack (removed from core in Rails 4.0)
|
4
|
+
Action caching for Action Pack (removed from core in Rails 4.0).
|
5
5
|
|
6
6
|
Installation
|
7
7
|
------------
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'actionpack-action_caching'
|
13
|
+
```
|
12
14
|
|
13
15
|
And then execute:
|
14
16
|
|
@@ -28,12 +30,14 @@ that filters run before the cache is served, which allows for
|
|
28
30
|
authentication and other restrictions on whether someone is allowed
|
29
31
|
to execute such action.
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
```ruby
|
34
|
+
class ListsController < ApplicationController
|
35
|
+
before_action :authenticate, except: :public
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
caches_page :public
|
38
|
+
caches_action :index, :show
|
39
|
+
end
|
40
|
+
```
|
37
41
|
|
38
42
|
In this example, the `public` action doesn't require authentication
|
39
43
|
so it's possible to use the faster page caching. On the other hand
|
@@ -54,56 +58,66 @@ Different representations of the same resource, e.g.
|
|
54
58
|
`http://david.example.com/lists.xml`
|
55
59
|
are treated like separate requests and so are cached separately.
|
56
60
|
Keep in mind when expiring an action cache that
|
57
|
-
`action:
|
58
|
-
`action:
|
61
|
+
`action: "lists"` is not the same as
|
62
|
+
`action: "list", format: :xml`.
|
59
63
|
|
60
64
|
You can modify the default action cache path by passing a
|
61
65
|
`:cache_path` option. This will be passed directly to
|
62
66
|
`ActionCachePath.new`. This is handy for actions with
|
63
67
|
multiple possible routes that should be cached differently. If a
|
64
|
-
|
68
|
+
proc (or an object that responds to `to_proc`) is given, it is
|
69
|
+
called with the current controller instance.
|
65
70
|
|
66
|
-
And you can also use `:if` (or `:unless`) to
|
67
|
-
|
71
|
+
And you can also use `:if` (or `:unless`) to control when the action
|
72
|
+
should be cached, similar to how you use them with `before_action`.
|
68
73
|
|
69
74
|
As of Rails 3.0, you can also pass `:expires_in` with a time
|
70
75
|
interval (in seconds) to schedule expiration of the cached item.
|
71
76
|
|
72
77
|
The following example depicts some of the points made above:
|
73
78
|
|
74
|
-
|
75
|
-
|
79
|
+
```ruby
|
80
|
+
class ListsController < ApplicationController
|
81
|
+
before_action :authenticate, except: :public
|
76
82
|
|
77
|
-
|
83
|
+
# simple fragment cache
|
84
|
+
caches_action :current
|
78
85
|
|
79
|
-
|
80
|
-
|
81
|
-
|
86
|
+
# expire cache after an hour
|
87
|
+
caches_action :archived, expires_in: 1.hour
|
88
|
+
|
89
|
+
# cache unless it's a JSON request
|
90
|
+
caches_action :index, unless: -> { request.format.json? }
|
91
|
+
|
92
|
+
# custom cache path
|
93
|
+
caches_action :show, cache_path: { project: 1 }
|
82
94
|
|
83
|
-
|
84
|
-
|
95
|
+
# custom cache path with a proc
|
96
|
+
caches_action :history, cache_path: -> { request.domain }
|
85
97
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
98
|
+
# custom cache path with a symbol
|
99
|
+
caches_action :feed, cache_path: :user_cache_path
|
100
|
+
|
101
|
+
protected
|
102
|
+
def user_cache_path
|
103
|
+
if params[:user_id]
|
104
|
+
user_list_url(params[:user_id], params[:id])
|
105
|
+
else
|
106
|
+
list_url(params[:id])
|
92
107
|
end
|
93
108
|
end
|
109
|
+
end
|
110
|
+
```
|
94
111
|
|
95
112
|
If you pass `layout: false`, it will only cache your action
|
96
113
|
content. That's useful when your layout has dynamic information.
|
97
114
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
The `:format` parameter is taken into account though. The safest
|
106
|
-
way to cache by MIME type is to pass the format in the route.
|
115
|
+
Note: Both the `:format` param and the `Accept` header are taken
|
116
|
+
into account when caching the fragment with the `:format` having
|
117
|
+
precedence. For backwards compatibility when the `Accept` header
|
118
|
+
indicates a HTML request the fragment is stored without the
|
119
|
+
extension but if an explicit `"html"` is passed in `:format` then
|
120
|
+
that _is_ used for storing the fragment.
|
107
121
|
|
108
122
|
Contributing
|
109
123
|
------------
|
@@ -113,3 +127,8 @@ Contributing
|
|
113
127
|
3. Commit your changes (`git commit -am 'Add some feature'`).
|
114
128
|
4. Push to the branch (`git push origin my-new-feature`).
|
115
129
|
5. Create a new Pull Request.
|
130
|
+
|
131
|
+
Code Status
|
132
|
+
-----------
|
133
|
+
|
134
|
+
* [](https://travis-ci.org/rails/actionpack-action_caching)
|