forked from railsdoc/railsdoc.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassMethods.html
More file actions
115 lines (57 loc) · 2.62 KB
/
ClassMethods.html
File metadata and controls
115 lines (57 loc) · 2.62 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
title: AbstractController::Caching::Fragments::ClassMethods
layout: default
---
<div class="main">
<div class="banner">
<span>Ruby on Rails 8.1.0</span><br />
<div class="type">module</div>
<h1>
AbstractController::Caching::Fragments::ClassMethods
</h1>
</div>
<div id="bodyContent">
<div id="content">
<h2 id="methods">Methods</h2>
<ul>
<li>
<a href="#method-i-fragment_cache_key">fragment_cache_key</a>
</li>
</ul>
<!-- Methods -->
<h2 id="instance-public-methods">Instance Public methods</h2>
<div class="method">
<h3 id="method-i-fragment_cache_key"><code><b>fragment_cache_key</b>(value = nil, &key)</code></h3>
<div class="description">
<p>Allows you to specify controller-wide key prefixes for cache fragments. Pass either a constant <code>value</code>, or a block which computes a value each time a cache key is generated.</p>
<p>For example, you may want to prefix all fragment cache keys with a global version identifier, so you can easily invalidate all caches.</p>
<pre><code>class ApplicationController
fragment_cache_key "v1"
end
</code></pre>
<p>When it’s time to invalidate all fragments, simply change the string constant. Or, progressively roll out the cache invalidation using a computed value:</p>
<pre><code>class ApplicationController
fragment_cache_key do
@account.id.odd? ? "v1" : "v2"
end
end
</code></pre>
</div>
<details class="method__source">
<summary>
<span class="label">📝 Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/caching/fragments.rb, line 58
def fragment_cache_key(value = nil, &key)
self.fragment_cache_keys += [key || -> { value }]
end</code></pre>
<a href="https://github.com/rails/rails/blob/1cdd190a25e483b65f1f25bbd0f13a25d696b461/actionpack/lib/abstract_controller/caching/fragments.rb#L58" target="_blank" class="github_url">🔎 See on GitHub</a>
</details>
</div>
<h2>Definition files</h2>
<ul class="files">
<li><a href="../../../../files/actionpack/lib/abstract_controller/caching/fragments_rb.html">actionpack/lib/abstract_controller/caching/fragments.rb</a></li>
</ul>
</div>
</div>
</div>