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

How to resolve the template digest #17

Open
levonmaa opened this issue Jan 17, 2018 · 3 comments
Open

How to resolve the template digest #17

levonmaa opened this issue Jan 17, 2018 · 3 comments

Comments

@levonmaa
Copy link

Curently I have a template that has the following

Rails.cache.fetch( ['v1', assignment] ) do
{
  id: assignment.id,
  description: assignment.description,
  start: assignment.start,
  end: assignment.end
}
end

And it caches out nicely.

But when I edit the template contents, say add a new item there, the cache does not invalidate. I know that ActionView::Helpers::CacheHelpers has functionality for this, but how to take advantage of it?

@binarydev
Copy link

You can manually clear the cache with Rails.cache.clear, or use the expires_in param of fetch to force the cache to invalidate after a few hours or days. Cachehelpers will normally only invalidate the cache if the object you’re caching with (assignment) has been modified in a way that touches the updated_at field, unless you’re providing a static key. Since this is a structural change of the template though that would affect all assignments, I would just clear the cache of the server when you deploy the updated code.

@chadwilken
Copy link

I think @levonmaa has a valid concern/idea. We use jb extensively and going in and manually expiring cache can be rather nettlesome. It would be useful to expire the cache of the template when it changes.

@m-kind
Copy link

m-kind commented Oct 29, 2020

Two late thoughts on that:

  1. v1 is not being used within the template and maybe it shouldn't be used anywhere else. So use it as a version number and make sure to increase it anytime you change the structure of the template. If you can't: introduce another string element carrying a version number as part of the cache key. You're editing the template anyway...
  2. In this case you already have assignment and (at least it looks like) there are no further heavy computations involved. Is it really worth employing the Rails cache (e.g. Redis calls) here? This even requires some kind of serialisation of assignment to use it as a cache key, I assume. I haven't made a performance analysis, of course...

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

No branches or pull requests

4 participants