cache_digests 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -14
- data/README.md +7 -3
- data/cache_digests-0.2.0.gem +0 -0
- data/cache_digests.gemspec +1 -1
- data/lib/cache_digests/dependency_tracker.rb +3 -2
- data/lib/cache_digests/engine.rb +3 -0
- data/lib/cache_digests/fragment_helper.rb +1 -1
- data/test/dependency_tracker_test.rb +34 -6
- data/test/fixtures/messages/show.html.erb +2 -1
- data/test/fragment_helper_test.rb +2 -2
- data/test/template_digestor_test.rb +6 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6b191158fb82947743671a747eae7ec82135d1e
|
4
|
+
data.tar.gz: 4b3932dc270e0f102462e72922b59b3932aee880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e3811d2d0a480fca0b2916ffed77813e06337a8df7c978c1ddc4545a085c2829722a3dd54c4e42daf31945cc3e7e8b45704b7ff791ac17fc4fe85a31e9a0b64
|
7
|
+
data.tar.gz: 7db33b78d9600286cd5ae69c40a703de3cf7169eaa922f0de05cbd7ee58c68eed32f903a92d62ec3ca68727fbb6f95b99cdec98522eb87feb960b7a5a24e5bda
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cache_digests (0.
|
4
|
+
cache_digests (0.3.0)
|
5
5
|
actionpack (>= 3.2)
|
6
6
|
thread_safe
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionpack (3.2.
|
12
|
-
activemodel (= 3.2.
|
13
|
-
activesupport (= 3.2.
|
11
|
+
actionpack (3.2.13)
|
12
|
+
activemodel (= 3.2.13)
|
13
|
+
activesupport (= 3.2.13)
|
14
14
|
builder (~> 3.0.0)
|
15
15
|
erubis (~> 2.7.0)
|
16
16
|
journey (~> 1.0.4)
|
@@ -18,26 +18,26 @@ GEM
|
|
18
18
|
rack-cache (~> 1.2)
|
19
19
|
rack-test (~> 0.6.1)
|
20
20
|
sprockets (~> 2.2.1)
|
21
|
-
activemodel (3.2.
|
22
|
-
activesupport (= 3.2.
|
21
|
+
activemodel (3.2.13)
|
22
|
+
activesupport (= 3.2.13)
|
23
23
|
builder (~> 3.0.0)
|
24
|
-
activesupport (3.2.
|
25
|
-
i18n (
|
24
|
+
activesupport (3.2.13)
|
25
|
+
i18n (= 0.6.1)
|
26
26
|
multi_json (~> 1.0)
|
27
|
-
atomic (1.
|
27
|
+
atomic (1.1.8)
|
28
28
|
builder (3.0.4)
|
29
29
|
erubis (2.7.0)
|
30
|
-
hike (1.2.
|
30
|
+
hike (1.2.2)
|
31
31
|
i18n (0.6.1)
|
32
32
|
journey (1.0.4)
|
33
|
-
minitest (
|
34
|
-
multi_json (1.
|
33
|
+
minitest (4.7.3)
|
34
|
+
multi_json (1.7.2)
|
35
35
|
rack (1.4.5)
|
36
36
|
rack-cache (1.2)
|
37
37
|
rack (>= 0.4)
|
38
38
|
rack-test (0.6.2)
|
39
39
|
rack (>= 1.0)
|
40
|
-
rake (0.
|
40
|
+
rake (10.0.4)
|
41
41
|
sprockets (2.2.2)
|
42
42
|
hike (~> 1.2)
|
43
43
|
multi_json (~> 1.0)
|
@@ -45,7 +45,7 @@ GEM
|
|
45
45
|
tilt (~> 1.1, != 1.3.0)
|
46
46
|
thread_safe (0.1.0)
|
47
47
|
atomic
|
48
|
-
tilt (1.3.
|
48
|
+
tilt (1.3.7)
|
49
49
|
|
50
50
|
PLATFORMS
|
51
51
|
ruby
|
data/README.md
CHANGED
@@ -63,9 +63,6 @@ Our code from above can just look like:
|
|
63
63
|
|
64
64
|
The caching key for app/views/projects/show.html.erb will be something like `views/projects/605816632-20120810191209/d9fb66b120b61f46707c67ab41d93cb2`. That last bit is a MD5 of the template file itself and all of its dependencies. It'll change if you change either the template or any of the dependencies, and thus allow the cache to expire automatically.
|
65
65
|
|
66
|
-
Note that if your application cache is enabled, the template digest will not be recomputed until you restart your application and you will have to restart the app whenever you change template code.
|
67
|
-
For development environment you might want to cache your fragments AND have dependent partials changes detected (with the penalty of recomputing the digests for each request). For that you can add `CacheDigests::TemplateDigestor.cache = ActiveSupport::Cache::NullStore.new` to your development configuration
|
68
|
-
|
69
66
|
You can use these handy rake tasks to see how deep the rabbit hole goes:
|
70
67
|
|
71
68
|
```
|
@@ -92,6 +89,13 @@ $ rake cache_digests:nested_dependencies TEMPLATE=projects/show
|
|
92
89
|
```
|
93
90
|
Note: this rake task doesn't differentiate between dependencies that are cached and dependencies that aren't - it is meant to show you all the dependencies of your view that cache_digests is able to derive.
|
94
91
|
|
92
|
+
Recomputing digests after updating a template
|
93
|
+
---------------------------------------------
|
94
|
+
|
95
|
+
If your application's environment has caching enabled with `config.action_view.cache_template_loading` (e.g. production) then template digests are only computed once and saved until the application is restarted. Any updates to a template will require an application restart in order for the template source and digest changes to be reflected. If `config.action_view.cache_template_loading` is unset then it is set to the value of `config.cache_classes` by default.
|
96
|
+
|
97
|
+
For environments that do not enable `config.action_view.cache_template_loading` (e.g. development) the default `CacheDigests::TemplateDigestor.cache` store is set to `ActiveSupport::Cache::NullStore.new`. This cache implementation doesn't actually store anything which forces template digests to recompute on every request. This is useful for cases where you want to test fragment caching (by enabling `config.action_controller.perform_caching`) or add template digests to your ETags with [rails/etagger](https://github.com/rails/etagger) but still allow templates and digests to reload any time a template is changed.
|
98
|
+
|
95
99
|
Implicit dependencies
|
96
100
|
---------------------
|
97
101
|
|
Binary file
|
data/cache_digests.gemspec
CHANGED
@@ -39,7 +39,7 @@ module CacheDigests
|
|
39
39
|
render\s* # render, followed by optional whitespace
|
40
40
|
\(? # start an optional parenthesis for the render call
|
41
41
|
(partial:|:partial\s+=>)?\s* # naming the partial, used with collection -- 1st capture
|
42
|
-
([@a-z"'][
|
42
|
+
([@a-z"'][@\w\/\."']+) # the template name itself -- 2nd capture
|
43
43
|
/x
|
44
44
|
|
45
45
|
def self.call(name, template)
|
@@ -72,7 +72,8 @@ module CacheDigests
|
|
72
72
|
# render(@topic) => render("topics/topic")
|
73
73
|
# render(topics) => render("topics/topic")
|
74
74
|
# render(message.topics) => render("topics/topic")
|
75
|
-
|
75
|
+
# render(message.topic) => render("topics/topic")
|
76
|
+
collect { |name| name.sub(/\A@?([a-z_]+\.)*([\w]+)\z/) { "#{$2.pluralize}/#{$2.singularize}" } }.
|
76
77
|
|
77
78
|
# render("headline") => render("message/headline")
|
78
79
|
collect { |name| name.include?("/") ? name : "#{directory}/#{name}" }.
|
data/lib/cache_digests/engine.rb
CHANGED
@@ -5,6 +5,9 @@ module CacheDigests
|
|
5
5
|
|
6
6
|
ActiveSupport.on_load :action_view do
|
7
7
|
ActionView::Base.send :include, CacheDigests::FragmentHelper
|
8
|
+
unless ActionView::Base.cache_template_loading
|
9
|
+
CacheDigests::TemplateDigestor.cache = ActiveSupport::Cache::NullStore.new
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
10
13
|
ActiveSupport.on_load :action_controller do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module CacheDigests
|
2
2
|
module FragmentHelper
|
3
|
-
def fragment_name_with_digest(name, dependencies)
|
3
|
+
def fragment_name_with_digest(name, dependencies=[])
|
4
4
|
[*name, TemplateDigestor.digest(@virtual_path, formats.last.to_sym, lookup_context, dependencies: dependencies)]
|
5
5
|
end
|
6
6
|
|
@@ -14,15 +14,15 @@ module ActionView
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
class
|
18
|
-
|
19
|
-
attr_reader :source, :handler
|
17
|
+
class FakeTemplate
|
18
|
+
attr_reader :source, :handler
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
20
|
+
def initialize(source, handler)
|
21
|
+
@source, @handler = source, handler
|
24
22
|
end
|
23
|
+
end
|
25
24
|
|
25
|
+
class DependencyTrackerTest < MiniTest::Unit::TestCase
|
26
26
|
def tracker
|
27
27
|
CacheDigests::DependencyTracker
|
28
28
|
end
|
@@ -47,3 +47,31 @@ class DependencyTrackerTest < MiniTest::Unit::TestCase
|
|
47
47
|
assert_equal [], dependencies
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
class ERBTrackerTest < MiniTest::Unit::TestCase
|
52
|
+
def make_tracker(name, template)
|
53
|
+
CacheDigests::DependencyTracker::ERBTracker.new(name, template)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_dependency_of_erb_template_with_number_in_filename
|
57
|
+
template = FakeTemplate.new("<%# render 'messages/message123' %>", :erb)
|
58
|
+
tracker = make_tracker('messages/_message123', template)
|
59
|
+
|
60
|
+
assert_equal ["messages/message123"], tracker.dependencies
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_finds_dependency_in_correct_directory
|
64
|
+
template = FakeTemplate.new("<%# render(message.topic) %>", :erb)
|
65
|
+
tracker = make_tracker('messages/_message', template)
|
66
|
+
|
67
|
+
assert_equal ["topics/topic"], tracker.dependencies
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_finds_dependency_in_correct_directory_with_underscore
|
71
|
+
template = FakeTemplate.new("<%# render(message_type.messages) %>", :erb)
|
72
|
+
tracker = make_tracker('message_types/_message_type', template)
|
73
|
+
|
74
|
+
assert_equal ["messages/message"], tracker.dependencies
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -58,12 +58,12 @@ class FragmentHelperTest < MiniTest::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_appends_the_key_with_digest
|
61
|
-
key_with_digest = fragmenter.fragment_name_with_digest("key"
|
61
|
+
key_with_digest = fragmenter.fragment_name_with_digest("key")
|
62
62
|
assert_equal ['key', 'digest'], key_with_digest
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_appends_the_array_key_with_digest
|
66
|
-
key_with_digest = fragmenter.fragment_name_with_digest(["key1", "key2"]
|
66
|
+
key_with_digest = fragmenter.fragment_name_with_digest(["key1", "key2"])
|
67
67
|
assert_equal ['key1', 'key2', 'digest'], key_with_digest
|
68
68
|
end
|
69
69
|
|
@@ -101,6 +101,12 @@ class TemplateDigestorTest < MiniTest::Unit::TestCase
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
def test_logging_of_missing_template_with_number_in_filename
|
105
|
+
assert_logged "Couldn't find template for digesting: messages/message123.html" do
|
106
|
+
digest("messages/show")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
104
110
|
def test_nested_template_directory
|
105
111
|
assert_digest_difference("messages/show") do
|
106
112
|
change_template("messages/actions/_move")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_digests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.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: 2013-
|
11
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -72,6 +72,7 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
+
- ./cache_digests-0.2.0.gem
|
75
76
|
- ./cache_digests.gemspec
|
76
77
|
- ./Gemfile
|
77
78
|
- ./Gemfile.lock
|
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
122
|
version: '0'
|
122
123
|
requirements: []
|
123
124
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.0.
|
125
|
+
rubygems_version: 2.0.2
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Nested fragment caches with (even) less situps
|