Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use page version's updated_at timestamp as cache key #2862

Merged

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented May 7, 2024

What is this pull request for?

Currently, it's hard for us to invalidate caches for Alchemy pages when content that's referenced through ingredients with related objects changes.

For example, in a situation where a user combines Alchemy and Solidus using the alchemy_solidus gem, a page's cache key does not update when a product that's referenced through a SpreeProduct ingredient changes.

There's a PR up on the alchemy_solidus gem that touches ingredients in these situations, and with this change, that touching can be used for breaking caches. [1]

1

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

@mamhoff mamhoff requested a review from a team as a code owner May 7, 2024 15:01
Copy link

codecov bot commented May 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.93%. Comparing base (f6b6ad5) to head (6787e96).
Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2862      +/-   ##
==========================================
+ Coverage   95.86%   95.93%   +0.07%     
==========================================
  Files         229      229              
  Lines        6211     6224      +13     
==========================================
+ Hits         5954     5971      +17     
+ Misses        257      253       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A published version is not guaranteed

app/models/alchemy/page/page_natures.rb Outdated Show resolved Hide resolved
@mamhoff mamhoff force-pushed the use-updated-at-timestamp-as-cache-key branch from 7cdcf7a to 215ba02 Compare May 8, 2024 07:47
app/models/alchemy/page/page_natures.rb Outdated Show resolved Hide resolved
spec/models/alchemy/page_spec.rb Outdated Show resolved Hide resolved
@tvdeyen tvdeyen added this to the 7.2 milestone May 8, 2024
@mamhoff mamhoff force-pushed the use-updated-at-timestamp-as-cache-key branch 2 times, most recently from c3ab762 to de87501 Compare May 8, 2024 12:04
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code wise 👍🏻 but want to test this in some apps thoroughly before merging and releasing

Currently, it's hard for us to invalidate caches for Alchemy pages when
content that's referenced through ingredients with related objects
changes.

For example, in a situation where a user combines Alchemy and Solidus
using the `alchemy_solidus` gem, a page's cache key does not update when
a product that's referenced through a SpreeProduct ingredient changes.

There's a PR up on the alchemy_solidus gem that touches ingredients in
these situations, and with this change, that touching can be used for
breaking caches. [1]

In the unlikely event the requested version is not available, we use the
page's updated_at timestamp as a fallback.

The core of the logic has been moved to a new `#last_modified_at`
method that can be used for the last-modified header in HTTP responses.
[1](AlchemyCMS/alchemy-solidus#108)
@mamhoff mamhoff force-pushed the use-updated-at-timestamp-as-cache-key branch 3 times, most recently from 3eb93f9 to 38e4c42 Compare May 13, 2024 13:47
Without this, the previous commit will not do what we expect. If we
don´t update the page version's updated at, it will not serve as a good
cache invalidator.
@mamhoff mamhoff force-pushed the use-updated-at-timestamp-as-cache-key branch from 38e4c42 to 7383a02 Compare May 14, 2024 06:38
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally. Works as expected. Thanks

app/models/alchemy/page/page_natures.rb Outdated Show resolved Hide resolved
app/models/alchemy/page/page_natures.rb Outdated Show resolved Hide resolved
app/models/alchemy/page/page_natures.rb Outdated Show resolved Hide resolved
@mamhoff mamhoff force-pushed the use-updated-at-timestamp-as-cache-key branch from 7597fd6 to 6787e96 Compare May 15, 2024 08:36
@tvdeyen tvdeyen merged commit 6af974a into AlchemyCMS:main May 15, 2024
36 checks passed
@mamhoff mamhoff deleted the use-updated-at-timestamp-as-cache-key branch May 28, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants