Commit 8891ea1
committed
Use fetch_multi instead of fetch
This will improve the performance since we are going to hit the backend
just once to read all keys, as long the cache adapter implements fetch
multi support like dalli.
For example:
builder.cache! :x do |cache|
cache.x true
end
builder.cache! :y do |cache|
cache.y true
end
builder.cache! :z do |cache|
cache.z true
end
This example was hitting the memcached 6 times on cache miss:
1. read x
2. write x
3. read y
4. write y
5. read z
6. write z
And 3 times on cache hit:
1. read x
2. read y
3. read z
After this change, 4 times on cache miss:
1. read multi x,y,z
2. write x
3. write y
4. write z
And 1 time on cache hit:
1. read multi x,y,z
Note that in the case of different options, one read multi will be made
per each options, i.e.:
builder.cache! :x do |cache|
cache.x true
end
builder.cache! :y do |cache|
cache.y true
end
builder.cache! :z, expires_in: 10.minutes do |cache|
cache.z true
end
builder.cache! :w, expires_in: 10.minutes do |cache|
cache.w true
end
In the case of cache miss:
1. read multi x,y
2. write x
3. write y
4. read multi z,w
5. write z
5. write w
In the case of cache hit:
1. read multi x,y
2. read multi z,w
That's because Rails.cache.fetch_multi signature is limited to use the
same options for all given keys.
And for last, nested cache calls are allowed and will follow recursively
to accomplish the same behavior, i.e.:
builder.cache! :x do |cache_x|
cache_x.x true
cache_x.cache! :y do |cache_y|
cache_y.y true
end
cache_x.cache! :z do |cache_z|
cache_z.z true
end
end
builder.cache! :w do |cache_w|
cache_w.w true
end
In the case of cache miss:
1. read multi x,w
2. read multi y,z
3. write y
4. write z
5. write x
6. write w
In the case of cache hit:
1. read multi x,w
The same rule of options will be applied, if you have different options,
one hit per options.
Pretty much the same of rails/jbuilder#421.1 parent 8e4d0bf commit 8891ea1
File tree
6 files changed
+240
-35
lines changed- lib
- abstract_builder
- spec
- abstract_builder
6 files changed
+240
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
70 | 73 | | |
71 | 74 | | |
72 | 75 | | |
73 | | - | |
74 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
78 | 83 | | |
79 | | - | |
80 | | - | |
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
| |||
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
91 | 98 | | |
92 | 99 | | |
93 | 100 | | |
| |||
133 | 140 | | |
134 | 141 | | |
135 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
136 | 147 | | |
137 | 148 | | |
138 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
6 | 18 | | |
7 | 19 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
65 | | - | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
| 72 | + | |
| 73 | + | |
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
76 | | - | |
| 80 | + | |
77 | 81 | | |
78 | 82 | | |
79 | 83 | | |
80 | 84 | | |
| 85 | + | |
| 86 | + | |
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
| |||
220 | 226 | | |
221 | 227 | | |
222 | 228 | | |
223 | | - | |
| 229 | + | |
224 | 230 | | |
225 | | - | |
226 | | - | |
227 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
228 | 234 | | |
229 | | - | |
230 | | - | |
| 235 | + | |
| 236 | + | |
231 | 237 | | |
232 | 238 | | |
233 | | - | |
| 239 | + | |
234 | 240 | | |
235 | 241 | | |
236 | 242 | | |
| 243 | + | |
237 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
238 | 261 | | |
239 | 262 | | |
240 | 263 | | |
241 | 264 | | |
242 | 265 | | |
243 | | - | |
| 266 | + | |
244 | 267 | | |
245 | 268 | | |
246 | 269 | | |
| |||
249 | 272 | | |
250 | 273 | | |
251 | 274 | | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 275 | + | |
| 276 | + | |
257 | 277 | | |
258 | | - | |
259 | | - | |
260 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
261 | 281 | | |
262 | | - | |
263 | | - | |
| 282 | + | |
| 283 | + | |
264 | 284 | | |
265 | 285 | | |
266 | 286 | | |
267 | 287 | | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
268 | 307 | | |
269 | 308 | | |
270 | 309 | | |
271 | 310 | | |
272 | 311 | | |
273 | 312 | | |
274 | | - | |
275 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
276 | 318 | | |
277 | 319 | | |
278 | | - | |
| 320 | + | |
| 321 | + | |
279 | 322 | | |
280 | 323 | | |
281 | 324 | | |
| |||
303 | 346 | | |
304 | 347 | | |
305 | 348 | | |
306 | | - | |
| 349 | + | |
307 | 350 | | |
308 | | - | |
309 | | - | |
310 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
311 | 354 | | |
312 | | - | |
| 355 | + | |
313 | 356 | | |
314 | 357 | | |
315 | 358 | | |
316 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
317 | 370 | | |
318 | 371 | | |
319 | 372 | | |
| |||
0 commit comments