Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
e2af193
add component controlled cache
Oct 8, 2024
d71dc5f
add changelog
Oct 8, 2024
e7f7397
fix cacahe implementatation to work with all methods
Oct 15, 2024
9a21b4c
fix cacahe implementatation to work with all methods
Oct 15, 2024
6d2462e
fix lint
Oct 15, 2024
a8073b7
yeah I know it aint working, I am tired however, taking a nother look…
Oct 16, 2024
7163934
fix cache
Nov 5, 2024
fe41b05
fix lint
Nov 5, 2024
a415840
fix
Nov 5, 2024
f8215a2
modulerize code
Nov 5, 2024
05091d5
more cleanup
Nov 5, 2024
3d22c2b
Apply suggestions from code review
reeganviljoen Nov 7, 2024
f1773bd
Update lib/view_component/cacheable.rb
reeganviljoen Nov 7, 2024
ccc755a
fix alphebtization
reeganviljoen Nov 18, 2024
c9622eb
add cache suhggestions
reeganviljoen Nov 19, 2024
d142634
fix legacy ruby specs
reeganviljoen Nov 21, 2024
10ffb42
Apply suggestions from code review
reeganviljoen Mar 23, 2025
2c87f77
code review feedback
reeganviljoen Mar 26, 2025
2aa0b30
make module fully optional;
reeganviljoen Mar 26, 2025
d6a2516
fix specs
reeganviljoen Mar 26, 2025
6094406
fix lint
reeganviljoen Mar 26, 2025
e5de30e
fix coberage
reeganviljoen Mar 26, 2025
8e971d5
add inherited component test
reeganviljoen Mar 26, 2025
f5c2fce
fix tests
reeganviljoen Mar 26, 2025
e3425a5
merge inherited values
reeganviljoen Mar 26, 2025
bc894d6
fix tests
reeganviljoen Mar 26, 2025
b79c3eb
fix lint
reeganviljoen Mar 26, 2025
60cf752
add polish
reeganviljoen Mar 27, 2025
48a222f
add wip docs
reeganviljoen Mar 27, 2025
bf9ea17
fix tests
reeganviljoen Mar 27, 2025
f6f19b7
fix lint
reeganviljoen Mar 27, 2025
87359f9
fix coverage
reeganviljoen Mar 27, 2025
4dcd622
fix lint
reeganviljoen Mar 27, 2025
17389e3
fix lint
reeganviljoen Mar 27, 2025
a6f7710
fix missing coverage
reeganviljoen Apr 1, 2025
13a4417
add format and varaiant to cache_digest
reeganviljoen Apr 1, 2025
d912555
add format and varaiant to cache_digest
reeganviljoen Apr 1, 2025
7413ad5
fix coverage
reeganviljoen Apr 1, 2025
7ed8d28
add retrive ccache key to be consistent with rails
reeganviljoen May 1, 2025
b2807a7
Fix linting
reeganviljoen May 1, 2025
a1d8421
fix changelog stuff
reeganviljoen May 1, 2025
d03928c
refactor cache logic
reeganviljoen May 2, 2025
64636b4
add identifier
reeganviljoen May 2, 2025
7876b14
compuye cache keys
reeganviljoen May 5, 2025
8a21be1
fix lint
reeganviljoen May 5, 2025
540b2d8
refactor
reeganviljoen May 6, 2025
1b2988a
add set
reeganviljoen May 6, 2025
cf313a9
Add cache refistry and alighn cache with how action view does it
reeganviljoen May 6, 2025
03683fe
namespace registry
reeganviljoen May 6, 2025
a0c74eb
add magic comment
reeganviljoen May 6, 2025
8f45ac8
fix failing rails 6 specs
reeganviljoen May 7, 2025
50943a1
Add the start of an actual digestor
reeganviljoen May 7, 2025
da7c685
add template digetor that usses an ast
reeganviljoen Jul 2, 2025
40b5040
refactor digetor a bit
reeganviljoen Jul 2, 2025
d9bb9f1
fix indentation
reeganviljoen Jul 2, 2025
52607fc
refactor
reeganviljoen Jul 3, 2025
c771954
get pr up top date
reeganviljoen Jul 3, 2025
5af2bc7
fix merge issue
reeganviljoen Jul 3, 2025
9d88e3a
try get tests to pass
reeganviljoen Jul 3, 2025
3542beb
try get tests to pass
reeganviljoen Jul 3, 2025
4f58de4
fix rails 8 test
reeganviljoen Jul 3, 2025
b75e0c2
fix soem artifcats
reeganviljoen Jul 3, 2025
1d81e9d
fix test
reeganviljoen Jul 3, 2025
35f68a8
make primer pass
reeganviljoen Jul 3, 2025
1102a50
fix linting
reeganviljoen Jul 3, 2025
b5a6587
fix linting
reeganviljoen Jul 3, 2025
299ff9d
fix alloactor spec
reeganviljoen Jul 3, 2025
9aa9dd0
fix tests
reeganviljoen Jul 3, 2025
f2df735
make primer pass
reeganviljoen Jul 3, 2025
9e93a5a
add inline erb cache component test
reeganviljoen Jul 3, 2025
aa4ff0d
Merge branch 'main' into rv_add_component_caching
joelhawksley Jul 14, 2025
189f212
Merge branch 'main' into rv_add_component_caching
Jan 28, 2026
250084b
fix ci
Jan 28, 2026
703ff01
fix primer ci failures by making ast lazy load dependecies
Jan 28, 2026
430616c
treat `temple`, `slim`, `haml` as optional dependencies (no boot-time…
Jan 28, 2026
0a0d319
fix ci
Jan 28, 2026
9e3767f
Refine fragment caching key + invalidation
Jan 28, 2026
3cc370b
Normalize cache_on dependencies and memoize digests
Jan 29, 2026
fdb9b40
update docs
Jan 29, 2026
63fd953
refactor dependecy extractor
Jan 29, 2026
a1b432e
Merge branch 'main' into rv_add_component_caching
reeganviljoen Jan 29, 2026
a91cc6e
Merge branch 'main' into rv_add_component_caching
joelhawksley Feb 4, 2026
9e4bc2a
Optimize digest and template dependency extraction
Jan 29, 2026
dfc6fe6
code review easy wins
Feb 12, 2026
2967a5e
code review: added a dedicated regression test for child partial depe…
Feb 12, 2026
4822177
code review: added shared integration-style spec approach from fork f…
Feb 12, 2026
805392d
code review: consider reusing parser approach from existing project i…
Feb 12, 2026
ac584e4
add cacing benchmark
Feb 12, 2026
2471962
Update docs/guide/caching.md
reeganviljoen Feb 12, 2026
3d4131a
fix code that was moved incorectly
Feb 12, 2026
a095f98
imrpove performnce
Feb 12, 2026
42d7f7b
add refactors to improve benchmarks
Feb 12, 2026
569fd91
make benchmark cmponents more expensive too really show ccache perfor…
Feb 12, 2026
2aaf6d8
Merge branch 'main' into rv_add_component_caching
Feb 12, 2026
797c0d5
fix ci
Feb 12, 2026
81648c1
fix ci
Feb 12, 2026
e70101e
add test for joels noted limitation
Feb 12, 2026
ca61171
fix tests
Feb 12, 2026
129765e
fix ci
Feb 12, 2026
98e2af9
use ActionviewPrecompiler instread of our own stuff
Feb 12, 2026
8c690b9
add action view precompiler
Feb 13, 2026
304c9f4
Merge branch 'main' into rv_add_component_caching
Feb 13, 2026
5d868d7
fix tests
Feb 13, 2026
c1afc0e
fix accidental commits
Feb 13, 2026
0208862
fix rails-main
Feb 13, 2026
bfa254b
fix rails main
Feb 13, 2026
cbb7d02
fix ci
Feb 13, 2026
78b526a
fix ci
Feb 13, 2026
d081520
fix rails main
Feb 13, 2026
074d380
fix vale issues
Feb 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ruby 4.0.1

12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
view_component (4.4.0)
actionview (>= 7.1.0)
actionview_precompiler (>= 0.4)
activesupport (>= 7.1.0)
concurrent-ruby (~> 1)

Expand Down Expand Up @@ -55,6 +56,8 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actionview_precompiler (0.4.0)
actionview (>= 6.0.a)
activejob (8.1.2)
activesupport (= 8.1.2)
globalid (>= 0.3.6)
Expand Down Expand Up @@ -145,6 +148,7 @@ GEM
temple (>= 0.8.2)
thor
tilt
herb (0.8.9)
herb (0.8.9-aarch64-linux-gnu)
herb (0.8.9-aarch64-linux-musl)
herb (0.8.9-arm-linux-gnu)
Expand Down Expand Up @@ -182,6 +186,7 @@ GEM
matrix (0.4.3)
method_source (1.1.0)
mini_mime (1.1.5)
mini_portile2 (2.8.9)
minitest (6.0.1)
prism (~> 1.5)
minitest-mock (5.27.0)
Expand All @@ -195,6 +200,9 @@ GEM
net-smtp (0.5.1)
net-protocol
nio4r (2.7.5)
nokogiri (1.19.0)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.19.0-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.0-aarch64-linux-musl)
Expand Down Expand Up @@ -466,6 +474,7 @@ CHECKSUMS
actionpack (8.1.2) sha256=ced74147a1f0daafaa4bab7f677513fd4d3add574c7839958f7b4f1de44f8423
actiontext (8.1.2) sha256=0bf57da22a9c19d970779c3ce24a56be31b51c7640f2763ec64aa72e358d2d2d
actionview (8.1.2) sha256=80455b2588911c9b72cec22d240edacb7c150e800ef2234821269b2b2c3e2e5b
actionview_precompiler (0.4.0) sha256=33b6bd6ec4c1b856e02fdf5f6512c9eb4a92ac1c0545e941b3e354b7d540ed1c
activejob (8.1.2) sha256=908dab3713b101859536375819f4156b07bdf4c232cc645e7538adb9e302f825
activemodel (8.1.2) sha256=e21358c11ce68aed3f9838b7e464977bc007b4446c6e4059781e1d5c03bcf33e
activerecord (8.1.2) sha256=acfbe0cadfcc50fa208011fe6f4eb01cae682ebae0ef57145ba45380c74bcc44
Expand Down Expand Up @@ -498,6 +507,7 @@ CHECKSUMS
ferrum (0.17.1) sha256=51d591120fc593e5a13b5d9d6474389f5145bb92a91e36eab147b5d096c8cbe7
globalid (1.3.0) sha256=05c639ad6eb4594522a0b07983022f04aa7254626ab69445a0e493aa3786ff11
haml (7.2.0) sha256=87fd2b71f7feab1724337b090a7d767f5ab2d42f08c974f3ead673f18cfcd55a
herb (0.8.9) sha256=8617e7eba753877cef231e3269a7e00788a9b67a91c3b79d1210ae20321b60f7
herb (0.8.9-aarch64-linux-gnu) sha256=9214cc24953c355f9ae785a95bb9362cdfc9fcd2ae4db2a32bc26c0b88f98c7f
herb (0.8.9-aarch64-linux-musl) sha256=4ee883eed0935cfe2e508d0843b015d689ef9d13f00e9ec4a81a35acd061dc13
herb (0.8.9-arm-linux-gnu) sha256=9f83c76899fecd5e3429bbd66728226e7b75539cc59283829041479381a6ceea
Expand All @@ -521,13 +531,15 @@ CHECKSUMS
matrix (0.4.3) sha256=a0d5ab7ddcc1973ff690ab361b67f359acbb16958d1dc072b8b956a286564c5b
method_source (1.1.0) sha256=181301c9c45b731b4769bc81e8860e72f9161ad7d66dd99103c9ab84f560f5c5
mini_mime (1.1.5) sha256=8681b7e2e4215f2a159f9400b5816d85e9d8c6c6b491e96a12797e798f8bccef
mini_portile2 (2.8.9) sha256=0cd7c7f824e010c072e33f68bc02d85a00aeb6fce05bb4819c03dfd3c140c289
minitest (6.0.1) sha256=7854c74f48e2e975969062833adc4013f249a4b212f5e7b9d5c040bf838d54bb
minitest-mock (5.27.0) sha256=7040ed7185417a966920987eaa6eaf1be4ea1fc5b25bb03ff4703f98564a55b0
net-imap (0.6.2) sha256=08caacad486853c61676cca0c0c47df93db02abc4a8239a8b67eb0981428acc6
net-pop (0.1.2) sha256=848b4e982013c15b2f0382792268763b748cce91c9e91e36b0f27ed26420dff3
net-protocol (0.2.2) sha256=aa73e0cba6a125369de9837b8d8ef82a61849360eba0521900e2c3713aa162a8
net-smtp (0.5.1) sha256=ed96a0af63c524fceb4b29b0d352195c30d82dd916a42f03c62a3a70e5b70736
nio4r (2.7.5) sha256=6c90168e48fb5f8e768419c93abb94ba2b892a1d0602cb06eef16d8b7df1dca1
nokogiri (1.19.0) sha256=e304d21865f62518e04f2bf59f93bd3a97ca7b07e7f03952946d8e1c05f45695
nokogiri (1.19.0-aarch64-linux-gnu) sha256=11a97ecc3c0e7e5edcf395720b10860ef493b768f6aa80c539573530bc933767
nokogiri (1.19.0-aarch64-linux-musl) sha256=eb70507f5e01bc23dad9b8dbec2b36ad0e61d227b42d292835020ff754fb7ba9
nokogiri (1.19.0-arm-linux-gnu) sha256=572a259026b2c8b7c161fdb6469fa2d0edd2b61cd599db4bbda93289abefbfe5
Expand Down
14 changes: 9 additions & 5 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ nav_order: 6

## main

* Add experimental support for caching by including `ViewComponent::ExperimentallyCacheable`.

*Reegan Viljoen*

## 4.4.0

* Fix segfaults when Ruby coverage is enabled.
Expand Down Expand Up @@ -552,7 +556,7 @@ This release makes the following breaking changes:

## 3.23.0

* Add docs about Slack channel in Ruby Central workspace. (Join us! #oss-view-component). Email joelhawksley@github.com for an invite.
* Add docs about Slack channel in Ruby Central workspace. (Join us! #oss-view-component). Email <joelhawksley@github.com> for an invite.

*Joel Hawksley

Expand Down Expand Up @@ -1912,7 +1916,7 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon

*Joel Hawksley*

* The ViewComponent team at GitHub is hiring! We're looking for a Rails engineer with accessibility experience: [https://boards.greenhouse.io/github/jobs/4020166](https://boards.greenhouse.io/github/jobs/4020166). Reach out to joelhawksley@github.com with any questions!
* The ViewComponent team at GitHub is hiring! We're looking for a Rails engineer with accessibility experience: [https://boards.greenhouse.io/github/jobs/4020166](https://boards.greenhouse.io/github/jobs/4020166). Reach out to <joelhawksley@github.com> with any questions!

* The ViewComponent team is hosting a happy hour at RailsConf. Join us for snacks, drinks, and stickers: [https://www.eventbrite.com/e/viewcomponent-happy-hour-tickets-304168585427](https://www.eventbrite.com/e/viewcomponent-happy-hour-tickets-304168585427)

Expand Down Expand Up @@ -2664,7 +2668,7 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon

*Matheus Richard*

* Are you interested in building the future of ViewComponent? GitHub is looking to hire a Senior Engineer to work on Primer ViewComponents and ViewComponent. Apply here: [US/Canada](https://github.com/careers) / [Europe](https://boards.greenhouse.io/github/jobs/3132294). Feel free to reach out to joelhawksley@github.com with any questions.
* Are you interested in building the future of ViewComponent? GitHub is looking to hire a Senior Engineer to work on Primer ViewComponents and ViewComponent. Apply here: [US/Canada](https://github.com/careers) / [Europe](https://boards.greenhouse.io/github/jobs/3132294). Feel free to reach out to <joelhawksley@github.com> with any questions.

*Joel Hawksley*

Expand All @@ -2682,7 +2686,7 @@ Run into an issue with this release? [Let us know](https://github.com/ViewCompon

## 2.31.0

_Note: This release includes an underlying change to Slots that may affect incorrect usage of the API, where Slots were set on a line prefixed by `<%=`. The result of setting a Slot shouldn't be returned. (`<%`)_
*Note: This release includes an underlying change to Slots that may affect incorrect usage of the API, where Slots were set on a line prefixed by `<%=`. The result of setting a Slot shouldn't be returned. (`<%`)*

* Add `#with_content` to allow setting content without a block.

Expand Down Expand Up @@ -3130,7 +3134,7 @@ _Note: This release includes an underlying change to Slots that may affect incor

* The gem name is now `view_component`.
* ViewComponent previews are now accessed at `/rails/view_components`.
* ViewComponents can _only_ be rendered with the instance syntax: `render(MyComponent.new)`. Support for all other syntaxes has been removed.
* ViewComponents can *only* be rendered with the instance syntax: `render(MyComponent.new)`. Support for all other syntaxes has been removed.
* ActiveModel::Validations have been removed. ViewComponent generators no longer include validations.
* In Rails 6.1, no monkey patching is used.
* `to_component_class` has been removed.
Expand Down
45 changes: 45 additions & 0 deletions docs/guide/caching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
layout: default
title: Caching
parent: How-to guide
---

# Caching

Experimental
{: .label }

Caching is experimental.

To enable caching, include `ViewComponent::ExperimentallyCacheable`.

Components implement caching by marking dependencies using `cache_on`:

```ruby
class CacheComponent < ViewComponent::Base
include ViewComponent::ExperimentallyCacheable

cache_on :foo, :bar
attr_reader :foo, :bar

def initialize(foo:, bar:)
@foo = foo
@bar = bar
end
end
```

```erb
<p><%= view_cache_dependencies.inspect %></p>

<p><%= Time.zone.now %></p>
<p><%= "#{foo} #{bar}" %></p>
```

`cache_on` accepts method names. Returned values are expanded via `ActiveSupport::Cache.expand_cache_key`, so Active Record models, `GlobalID`, arrays, and plain strings work as expected.

Methods listed in `cache_on` may be private.

The cache key includes a digest of component source (Ruby + templates + i18n sidecars) and rendered child ViewComponents.

Partial/layout string dependencies aren't currently included in the digest, to invalidate the cache on deploy modify `RAILS_CACHE_ID`/`RAILS_APP_VERSION`.
3 changes: 3 additions & 0 deletions gemfiles/rails_7.1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
view_component (4.4.0)
actionview (>= 7.1.0)
actionview_precompiler (>= 0.4)
activesupport (>= 7.1.0)
concurrent-ruby (~> 1)

Expand Down Expand Up @@ -60,6 +61,8 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actionview_precompiler (0.4.0)
actionview (>= 6.0.a)
activejob (7.1.6)
activesupport (= 7.1.6)
globalid (>= 0.3.6)
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/rails_7.2.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
view_component (4.4.0)
actionview (>= 7.1.0)
actionview_precompiler (>= 0.4)
activesupport (>= 7.1.0)
concurrent-ruby (~> 1)

Expand Down Expand Up @@ -55,6 +56,8 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actionview_precompiler (0.4.0)
actionview (>= 6.0.a)
activejob (7.2.3)
activesupport (= 7.2.3)
globalid (>= 0.3.6)
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/rails_8.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
view_component (4.4.0)
actionview (>= 7.1.0)
actionview_precompiler (>= 0.4)
activesupport (>= 7.1.0)
concurrent-ruby (~> 1)

Expand Down Expand Up @@ -52,6 +53,8 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actionview_precompiler (0.4.0)
actionview (>= 6.0.a)
activejob (8.0.4)
activesupport (= 8.0.4)
globalid (>= 0.3.6)
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/rails_8.1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
view_component (4.4.0)
actionview (>= 7.1.0)
actionview_precompiler (>= 0.4)
activesupport (>= 7.1.0)
concurrent-ruby (~> 1)

Expand Down Expand Up @@ -55,6 +56,8 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actionview_precompiler (0.4.0)
actionview (>= 6.0.a)
activejob (8.1.2)
activesupport (= 8.1.2)
globalid (>= 0.3.6)
Expand Down
Loading
Loading