Skip to content

Commit 4ed3f44

Browse files
committed
add wip docs
1 parent 19f986b commit 4ed3f44

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

docs/guide/caching.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)