cache_rocket 0.5.0 → 0.5.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 +4 -4
- data/README.md +17 -12
- data/lib/cache_rocket/fragment.rb +1 -1
- data/lib/cache_rocket/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 127bbbf2d03cd8f29d2fbf71eabe3f80f218088c
|
4
|
+
data.tar.gz: 231d24676b56a959e4fb988df98c9891098b7f16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df4ca70e460b54af44adb5539378b895e6dc86b384e8b3dd3b2024be7b2dd648105ca833bfee2f7ea10d029105623d81f1a8f5ba50fd9610c126946a92374db9
|
7
|
+
data.tar.gz: dc06d403bdb980ff4c3ca0c80ab5ef3e098fdfdaa18f8d22f1f2f409887ad4968d282b106b203044d312f15544751ec45b1ab2fa17416fe227f158c9357792f5
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Add the gem to your Gemfile:
|
|
22
22
|
gem 'cache_rocket'
|
23
23
|
```
|
24
24
|
|
25
|
-
Include the CacheRocket module so your views can use the `render_cached`
|
25
|
+
Include the CacheRocket module so your views can use the `cache_replace` and `render_cached` methods.
|
26
26
|
Most likely you would put this in your `ApplicationHelper`:
|
27
27
|
|
28
28
|
```ruby
|
@@ -32,11 +32,11 @@ include CacheRocket
|
|
32
32
|
## Use
|
33
33
|
|
34
34
|
CacheRocket allows you to cache a fragment of html and replace inner html.
|
35
|
-
You inject dynamic content into a
|
35
|
+
You inject dynamic content into a cached fragment that contains a placeholder.
|
36
36
|
|
37
37
|
### `cache_replace`
|
38
38
|
|
39
|
-
The simplest usage is inline with the `cache_replace`
|
39
|
+
The simplest usage is inline with the `cache_replace` method. It works
|
40
40
|
like Rails' `cache` method, plus it replaces content that you do not want
|
41
41
|
to cache because it is impractical or inefficient.
|
42
42
|
|
@@ -45,19 +45,24 @@ For example:
|
|
45
45
|
#### Before
|
46
46
|
|
47
47
|
```haml
|
48
|
-
.htmls
|
48
|
+
.lots.of.htmls
|
49
49
|
= Time.now
|
50
|
+
.more.htmls
|
51
|
+
= user.name
|
50
52
|
```
|
51
53
|
|
52
54
|
#### After
|
53
55
|
|
54
56
|
```haml
|
55
|
-
- cache_replace("
|
56
|
-
.htmls
|
57
|
+
- cache_replace("some-key", replace: { time: Time.now, name: user.name }) do
|
58
|
+
.lots.of.htmls
|
57
59
|
= cache_replace_key :time
|
60
|
+
.more.htmls
|
61
|
+
= cache_replace_key :name
|
58
62
|
```
|
59
63
|
|
60
|
-
Now the fragment is cached once with
|
64
|
+
Now the fragment is cached once with placeholders, and the time and user name are
|
65
|
+
replaced when rendered.
|
61
66
|
|
62
67
|
Obviously, the above example is contrived and would not result in any
|
63
68
|
performance benefit. When the block of html you are rendering is large,
|
@@ -168,14 +173,14 @@ render_cached 'outer', replace: ['inner', 'footer']
|
|
168
173
|
#### Hash of keys to replace with values
|
169
174
|
|
170
175
|
```ruby
|
171
|
-
render_cached 'outer', replace: { key_name:
|
176
|
+
render_cached 'outer', replace: { key_name: a_method(object) }
|
172
177
|
```
|
173
178
|
|
174
179
|
#### Block containing a hash of keys to replace with values
|
175
180
|
|
176
181
|
```ruby
|
177
182
|
render_cached 'outer' do
|
178
|
-
{ key_name:
|
183
|
+
{ key_name: a_method(object) }
|
179
184
|
end
|
180
185
|
```
|
181
186
|
|
@@ -183,14 +188,14 @@ end
|
|
183
188
|
|
184
189
|
```ruby
|
185
190
|
render_cached 'outer', collection: objects,
|
186
|
-
replace: { key_name: -> (object) {
|
191
|
+
replace: { key_name: -> (object) { a_method(object) } }
|
187
192
|
```
|
188
193
|
|
189
194
|
#### Render a collection with block syntax
|
190
195
|
|
191
196
|
```ruby
|
192
197
|
render_cached 'outer', collection: objects do
|
193
|
-
{ key_name: -> (object) {
|
198
|
+
{ key_name: -> (object) { a_method(object) } }
|
194
199
|
end
|
195
200
|
```
|
196
201
|
|
@@ -199,7 +204,7 @@ end
|
|
199
204
|
```ruby
|
200
205
|
render_cached 'outer', collection: objects do
|
201
206
|
{
|
202
|
-
key_1: -> (object) {
|
207
|
+
key_1: -> (object) { a_method(object) },
|
203
208
|
key_2: -> (item) { item.name },
|
204
209
|
}
|
205
210
|
end
|
data/lib/cache_rocket/version.rb
CHANGED