We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 19f986b commit 4ed3f44Copy full SHA for 4ed3f44
docs/guide/caching.md
@@ -0,0 +1,42 @@
1
+---
2
+layout: default
3
+title: Caching
4
+parent: How-to guide
5
6
+
7
+# Caching
8
9
+Experimental
10
+{: .label }
11
12
+Components can implement caching by marking the depndencies that a digest can be built om using the cache_on macro, like so:
13
14
+```ruby
15
+class CacheComponent < ViewComponent::Base
16
+ include ViewComponent::Cacheable
17
18
+ cache_on :foo, :bar
19
+ attr_reader :foo, :bar
20
21
+ def initialize(foo:, bar:)
22
+ @foo = foo
23
+ @bar = bar
24
+ end
25
+end
26
+```
27
28
+```erb
29
+<p><%= view_cache_dependencies %></p>
30
31
+<p><%= Time.zone.now %>"></p>
32
+<p><%= "#{foo} #{bar}" %></p>
33
34
35
+will result in
36
+```html
37
+<p>foo-bar</p>
38
39
+<p>2025-03-27 16:46:10 UTC</p>
40
+<p> foo bar</p>
41
42
0 commit comments