actionpack-action_caching 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +60 -10
- data/CHANGELOG.md +12 -1
- data/README.md +34 -29
- data/actionpack-action_caching.gemspec +3 -3
- 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/lib/action_controller/caching/actions.rb +1 -1
- data/test/caching_test.rb +45 -21
- metadata +6 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 13e2fb3bc82b8a207a5712370efc031c31510dc257dbd2c044edf1c26ac01c30
|
4
|
+
data.tar.gz: df99ab7f3623d4b4e2f1729f6cc3db276242f2362803606315b03c93bfe1cc7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96ab04f9ff4d0250f94229cb6fb70a4d85e8ed8e4c0068c626a9fb2e7dddb08809ec38b440f18a259cf17ab98d30bef17736d276cfeb5c2a99ce7f69a598c501
|
7
|
+
data.tar.gz: 478aa629c1579202d7a01d9e4f84062812136cbd8009f10bbaf91d72242d27678a76ee5277090959088522db01c81473e9170ba3bd2b37e0abd913dcee331d2d
|
data/.travis.yml
CHANGED
@@ -5,15 +5,18 @@ cache:
|
|
5
5
|
bundler: true
|
6
6
|
|
7
7
|
before_install:
|
8
|
-
- gem
|
8
|
+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
9
|
+
- gem install bundler -v '< 2'
|
9
10
|
|
10
11
|
rvm:
|
11
12
|
- 1.9.3
|
12
13
|
- 2.0.0
|
13
|
-
- 2.1.
|
14
|
-
- 2.2.
|
15
|
-
- 2.3.
|
16
|
-
- 2.4.
|
14
|
+
- 2.1.10
|
15
|
+
- 2.2.10
|
16
|
+
- 2.3.8
|
17
|
+
- 2.4.6
|
18
|
+
- 2.5.5
|
19
|
+
- 2.6.3
|
17
20
|
|
18
21
|
gemfile:
|
19
22
|
- Gemfile
|
@@ -21,6 +24,9 @@ gemfile:
|
|
21
24
|
- gemfiles/Gemfile-4-1-stable
|
22
25
|
- gemfiles/Gemfile-4-2-stable
|
23
26
|
- gemfiles/Gemfile-5-0-stable
|
27
|
+
- gemfiles/Gemfile-5-1-stable
|
28
|
+
- gemfiles/Gemfile-5-2-stable
|
29
|
+
- gemfiles/Gemfile-6-0-stable
|
24
30
|
- gemfiles/Gemfile-edge
|
25
31
|
|
26
32
|
matrix:
|
@@ -31,24 +37,68 @@ matrix:
|
|
31
37
|
gemfile: Gemfile
|
32
38
|
- rvm: 2.0.0
|
33
39
|
gemfile: Gemfile
|
34
|
-
- rvm: 2.1.
|
40
|
+
- rvm: 2.1.10
|
35
41
|
gemfile: Gemfile
|
36
42
|
- rvm: 1.9.3
|
37
43
|
gemfile: gemfiles/Gemfile-5-0-stable
|
44
|
+
- rvm: 1.9.3
|
45
|
+
gemfile: gemfiles/Gemfile-5-1-stable
|
46
|
+
- rvm: 1.9.3
|
47
|
+
gemfile: gemfiles/Gemfile-5-2-stable
|
48
|
+
- rvm: 1.9.3
|
49
|
+
gemfile: gemfiles/Gemfile-6-0-stable
|
38
50
|
- rvm: 2.0.0
|
39
51
|
gemfile: gemfiles/Gemfile-5-0-stable
|
40
|
-
- rvm: 2.
|
52
|
+
- rvm: 2.0.0
|
53
|
+
gemfile: gemfiles/Gemfile-5-1-stable
|
54
|
+
- rvm: 2.0.0
|
55
|
+
gemfile: gemfiles/Gemfile-5-2-stable
|
56
|
+
- rvm: 2.0.0
|
57
|
+
gemfile: gemfiles/Gemfile-6-0-stable
|
58
|
+
- rvm: 2.1.10
|
41
59
|
gemfile: gemfiles/Gemfile-5-0-stable
|
60
|
+
- rvm: 2.1.10
|
61
|
+
gemfile: gemfiles/Gemfile-5-1-stable
|
62
|
+
- rvm: 2.1.10
|
63
|
+
gemfile: gemfiles/Gemfile-5-2-stable
|
64
|
+
- rvm: 2.1.10
|
65
|
+
gemfile: gemfiles/Gemfile-6-0-stable
|
66
|
+
- rvm: 2.2.10
|
67
|
+
gemfile: gemfiles/Gemfile-6-0-stable
|
68
|
+
- rvm: 2.3.8
|
69
|
+
gemfile: gemfiles/Gemfile-6-0-stable
|
70
|
+
- rvm: 2.4.6
|
71
|
+
gemfile: gemfiles/Gemfile-6-0-stable
|
42
72
|
- rvm: 1.9.3
|
43
73
|
gemfile: gemfiles/Gemfile-edge
|
44
74
|
- rvm: 2.0.0
|
45
75
|
gemfile: gemfiles/Gemfile-edge
|
46
|
-
- rvm: 2.1.
|
76
|
+
- rvm: 2.1.10
|
77
|
+
gemfile: gemfiles/Gemfile-edge
|
78
|
+
- rvm: 2.2.10
|
47
79
|
gemfile: gemfiles/Gemfile-edge
|
48
|
-
- rvm: 2.
|
80
|
+
- rvm: 2.3.8
|
81
|
+
gemfile: gemfiles/Gemfile-edge
|
82
|
+
- rvm: 2.4.6
|
83
|
+
gemfile: gemfiles/Gemfile-edge
|
84
|
+
- rvm: 2.4.6
|
85
|
+
gemfile: gemfiles/Gemfile-4-0-stable
|
86
|
+
- rvm: 2.4.6
|
87
|
+
gemfile: gemfiles/Gemfile-4-1-stable
|
88
|
+
- rvm: 2.5.5
|
49
89
|
gemfile: gemfiles/Gemfile-4-0-stable
|
50
|
-
- rvm: 2.
|
90
|
+
- rvm: 2.5.5
|
51
91
|
gemfile: gemfiles/Gemfile-4-1-stable
|
92
|
+
- rvm: 2.6.3
|
93
|
+
gemfile: gemfiles/Gemfile-4-0-stable
|
94
|
+
- rvm: 2.6.3
|
95
|
+
gemfile: gemfiles/Gemfile-4-1-stable
|
96
|
+
- rvm: 2.6.3
|
97
|
+
gemfile: gemfiles/Gemfile-4-2-stable
|
98
|
+
- rvm: 2.6.3
|
99
|
+
gemfile: gemfiles/Gemfile-5-0-stable
|
100
|
+
- rvm: 2.6.3
|
101
|
+
gemfile: gemfiles/Gemfile-5-1-stable
|
52
102
|
|
53
103
|
notifications:
|
54
104
|
email: false
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
## 1.2.
|
1
|
+
## 1.2.1 (November 12, 2019)
|
2
|
+
|
3
|
+
* Fix HTML escaping when `:layout` is `false`.
|
4
|
+
|
5
|
+
*Anton Katunin*
|
6
|
+
|
7
|
+
* Add support to Rails 6.
|
8
|
+
|
9
|
+
*Jacob Bednarz*
|
10
|
+
|
11
|
+
|
12
|
+
## 1.2.0 (January 23, 2017)
|
2
13
|
|
3
14
|
* Support proc options with zero arguments
|
4
15
|
|
data/README.md
CHANGED
@@ -8,7 +8,9 @@ Installation
|
|
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
|
@@ -72,36 +76,38 @@ interval (in seconds) to schedule expiration of the cached item.
|
|
72
76
|
|
73
77
|
The following example depicts some of the points made above:
|
74
78
|
|
75
|
-
|
76
|
-
|
79
|
+
```ruby
|
80
|
+
class ListsController < ApplicationController
|
81
|
+
before_action :authenticate, except: :public
|
77
82
|
|
78
|
-
|
79
|
-
|
83
|
+
# simple fragment cache
|
84
|
+
caches_action :current
|
80
85
|
|
81
|
-
|
82
|
-
|
86
|
+
# expire cache after an hour
|
87
|
+
caches_action :archived, expires_in: 1.hour
|
83
88
|
|
84
|
-
|
85
|
-
|
89
|
+
# cache unless it's a JSON request
|
90
|
+
caches_action :index, unless: -> { request.format.json? }
|
86
91
|
|
87
|
-
|
88
|
-
|
92
|
+
# custom cache path
|
93
|
+
caches_action :show, cache_path: { project: 1 }
|
89
94
|
|
90
|
-
|
91
|
-
|
95
|
+
# custom cache path with a proc
|
96
|
+
caches_action :history, cache_path: -> { request.domain }
|
92
97
|
|
93
|
-
|
94
|
-
|
98
|
+
# custom cache path with a symbol
|
99
|
+
caches_action :feed, cache_path: :user_cache_path
|
95
100
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
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])
|
107
|
+
end
|
104
108
|
end
|
109
|
+
end
|
110
|
+
```
|
105
111
|
|
106
112
|
If you pass `layout: false`, it will only cache your action
|
107
113
|
content. That's useful when your layout has dynamic information.
|
@@ -126,4 +132,3 @@ Code Status
|
|
126
132
|
-----------
|
127
133
|
|
128
134
|
* [](https://travis-ci.org/rails/actionpack-action_caching)
|
129
|
-
* [](https://gemnasium.com/rails/actionpack-action_caching)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "actionpack-action_caching"
|
3
|
-
gem.version = "1.2.
|
3
|
+
gem.version = "1.2.1"
|
4
4
|
gem.author = "David Heinemeier Hansson"
|
5
5
|
gem.email = "david@loudthinking.com"
|
6
6
|
gem.description = "Action caching for Action Pack (removed from core in Rails 4.0)"
|
@@ -14,8 +14,8 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
gem.license = "MIT"
|
16
16
|
|
17
|
-
gem.add_dependency "actionpack", ">= 4.0.0"
|
17
|
+
gem.add_dependency "actionpack", ">= 4.0.0"
|
18
18
|
|
19
19
|
gem.add_development_dependency "mocha"
|
20
|
-
gem.add_development_dependency "activerecord", ">= 4.0.0"
|
20
|
+
gem.add_development_dependency "activerecord", ">= 4.0.0"
|
21
21
|
end
|
data/test/caching_test.rb
CHANGED
@@ -52,7 +52,7 @@ class ActionCachingTestController < CachingController
|
|
52
52
|
layout "talk_from_action"
|
53
53
|
|
54
54
|
def index
|
55
|
-
@cache_this =
|
55
|
+
@cache_this = CacheContent.to_s
|
56
56
|
render plain: @cache_this
|
57
57
|
end
|
58
58
|
|
@@ -66,17 +66,17 @@ class ActionCachingTestController < CachingController
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def with_layout
|
69
|
-
@cache_this =
|
69
|
+
@cache_this = CacheContent.to_s
|
70
70
|
render html: @cache_this, layout: true
|
71
71
|
end
|
72
72
|
|
73
73
|
def with_format_and_http_param
|
74
|
-
@cache_this =
|
74
|
+
@cache_this = CacheContent.to_s
|
75
75
|
render plain: @cache_this
|
76
76
|
end
|
77
77
|
|
78
78
|
def with_symbol_format
|
79
|
-
@cache_this =
|
79
|
+
@cache_this = CacheContent.to_s
|
80
80
|
render json: { timestamp: @cache_this }
|
81
81
|
end
|
82
82
|
|
@@ -126,7 +126,7 @@ class ActionCachingTestController < CachingController
|
|
126
126
|
end
|
127
127
|
|
128
128
|
def invalid
|
129
|
-
@cache_this =
|
129
|
+
@cache_this = CacheContent.to_s
|
130
130
|
|
131
131
|
respond_to do |format|
|
132
132
|
format.json { render json: @cache_this }
|
@@ -134,7 +134,7 @@ class ActionCachingTestController < CachingController
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def accept
|
137
|
-
@cache_this =
|
137
|
+
@cache_this = CacheContent.to_s
|
138
138
|
|
139
139
|
respond_to do |format|
|
140
140
|
format.html { render html: @cache_this }
|
@@ -174,10 +174,11 @@ class ActionCachingTestController < CachingController
|
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
|
-
class
|
178
|
-
|
179
|
-
|
180
|
-
|
177
|
+
class CacheContent
|
178
|
+
def self.to_s
|
179
|
+
# Let Time spicy to assure that Time.now != Time.now
|
180
|
+
time = Time.now.to_f + rand
|
181
|
+
(time.to_s + "<div />").html_safe
|
181
182
|
end
|
182
183
|
end
|
183
184
|
|
@@ -391,7 +392,7 @@ class ActionCacheTest < ActionController::TestCase
|
|
391
392
|
get "/action_caching_test", to: "action_caching_test#index"
|
392
393
|
end
|
393
394
|
|
394
|
-
|
395
|
+
CacheContent.expects(:to_s).returns('12345.0').once
|
395
396
|
@controller.expects(:read_fragment).with("hostname.com/action_caching_test", expires_in: 1.hour).once
|
396
397
|
@controller.expects(:write_fragment).with("hostname.com/action_caching_test", "12345.0", expires_in: 1.hour).once
|
397
398
|
get :index
|
@@ -582,9 +583,7 @@ class ActionCacheTest < ActionController::TestCase
|
|
582
583
|
assert fragment_exist?("hostname.com/action_caching_test/index.xml")
|
583
584
|
|
584
585
|
get :index, format: "xml"
|
585
|
-
|
586
|
-
assert_equal cached_time, @response.body
|
587
|
-
assert_equal "application/xml", @response.content_type
|
586
|
+
assert_cached(cached_time, "application/xml")
|
588
587
|
|
589
588
|
get :expire_xml
|
590
589
|
assert_response :success
|
@@ -603,7 +602,12 @@ class ActionCacheTest < ActionController::TestCase
|
|
603
602
|
get :index, params: { id: "content-type" }, format: "xml"
|
604
603
|
get :index, params: { id: "content-type" }, format: "xml"
|
605
604
|
assert_response :success
|
606
|
-
|
605
|
+
|
606
|
+
if @response.respond_to?(:media_type)
|
607
|
+
assert_equal "application/xml", @response.media_type
|
608
|
+
else
|
609
|
+
assert_equal "application/xml", @response.content_type
|
610
|
+
end
|
607
611
|
end
|
608
612
|
|
609
613
|
def test_correct_content_type_is_returned_for_cache_hit_on_action_with_string_key
|
@@ -615,7 +619,12 @@ class ActionCacheTest < ActionController::TestCase
|
|
615
619
|
get :show, format: "xml"
|
616
620
|
get :show, format: "xml"
|
617
621
|
assert_response :success
|
618
|
-
|
622
|
+
|
623
|
+
if @response.respond_to?(:media_type)
|
624
|
+
assert_equal "application/xml", @response.media_type
|
625
|
+
else
|
626
|
+
assert_equal "application/xml", @response.content_type
|
627
|
+
end
|
619
628
|
end
|
620
629
|
|
621
630
|
def test_correct_content_type_is_returned_for_cache_hit_on_action_with_string_key_from_proc
|
@@ -627,7 +636,12 @@ class ActionCacheTest < ActionController::TestCase
|
|
627
636
|
get :edit, params: { id: 1 }, format: "xml"
|
628
637
|
get :edit, params: { id: 1 }, format: "xml"
|
629
638
|
assert_response :success
|
630
|
-
|
639
|
+
|
640
|
+
if @response.respond_to?(:media_type)
|
641
|
+
assert_equal "application/xml", @response.media_type
|
642
|
+
else
|
643
|
+
assert_equal "application/xml", @response.content_type
|
644
|
+
end
|
631
645
|
end
|
632
646
|
|
633
647
|
def test_empty_path_is_normalized
|
@@ -850,16 +864,26 @@ class ActionCacheTest < ActionController::TestCase
|
|
850
864
|
get(*args)
|
851
865
|
end
|
852
866
|
|
853
|
-
def assert_cached(cache_time,
|
867
|
+
def assert_cached(cache_time, media_type = "text/html")
|
854
868
|
assert_response :success
|
855
869
|
assert_equal cache_time, @response.body
|
856
|
-
|
870
|
+
|
871
|
+
if @response.respond_to?(:media_type)
|
872
|
+
assert_equal media_type, @response.media_type
|
873
|
+
else
|
874
|
+
assert_equal media_type, @response.content_type
|
875
|
+
end
|
857
876
|
end
|
858
877
|
|
859
|
-
def assert_not_cached(cache_time,
|
878
|
+
def assert_not_cached(cache_time, media_type = "text/html")
|
860
879
|
assert_response :success
|
861
880
|
assert_not_equal cache_time, @response.body
|
862
|
-
|
881
|
+
|
882
|
+
if @response.respond_to?(:media_type)
|
883
|
+
assert_equal media_type, @response.media_type
|
884
|
+
else
|
885
|
+
assert_equal media_type, @response.content_type
|
886
|
+
end
|
863
887
|
end
|
864
888
|
|
865
889
|
def content_to_cache
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionpack-action_caching
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.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:
|
11
|
+
date: 2019-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 4.0.0
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '6'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,9 +24,6 @@ dependencies:
|
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 4.0.0
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '6'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: mocha
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -51,9 +45,6 @@ dependencies:
|
|
51
45
|
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: 4.0.0
|
54
|
-
- - "<"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '6'
|
57
48
|
type: :development
|
58
49
|
prerelease: false
|
59
50
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -61,9 +52,6 @@ dependencies:
|
|
61
52
|
- - ">="
|
62
53
|
- !ruby/object:Gem::Version
|
63
54
|
version: 4.0.0
|
64
|
-
- - "<"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '6'
|
67
55
|
description: Action caching for Action Pack (removed from core in Rails 4.0)
|
68
56
|
email: david@loudthinking.com
|
69
57
|
executables: []
|
@@ -84,6 +72,9 @@ files:
|
|
84
72
|
- gemfiles/Gemfile-4-1-stable
|
85
73
|
- gemfiles/Gemfile-4-2-stable
|
86
74
|
- gemfiles/Gemfile-5-0-stable
|
75
|
+
- gemfiles/Gemfile-5-1-stable
|
76
|
+
- gemfiles/Gemfile-5-2-stable
|
77
|
+
- gemfiles/Gemfile-6-0-stable
|
87
78
|
- gemfiles/Gemfile-edge
|
88
79
|
- lib/action_controller/action_caching.rb
|
89
80
|
- lib/action_controller/caching/actions.rb
|
@@ -111,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
102
|
- !ruby/object:Gem::Version
|
112
103
|
version: '0'
|
113
104
|
requirements: []
|
114
|
-
|
115
|
-
rubygems_version: 2.6.8
|
105
|
+
rubygems_version: 3.0.2
|
116
106
|
signing_key:
|
117
107
|
specification_version: 4
|
118
108
|
summary: Action caching for Action Pack (removed from core in Rails 4.0)
|