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

Automatically clear entity cache after save/update? #5335

Open
laryn opened this issue Oct 28, 2021 · 3 comments
Open

Automatically clear entity cache after save/update? #5335

laryn opened this issue Oct 28, 2021 · 3 comments

Comments

@laryn
Copy link
Contributor

laryn commented Oct 28, 2021

Description of the bug

I've noticed in a variety of contexts that it takes a long time for changes to register after adding or updating nodes, comments, etc. and I believe this is due to entity cache being added to core.

One example that was fixed in contrib was here, in webform civicrm:

I'm also working with a site that has reported that nobody's replies are showing up in a forum, which turned out to be a cache issue. I've added cache_clear_all($comment->cid, 'cache_entity_comment'); in a hook_comment_insert() and hook_comment_update() but I'm wondering if we should clear the targeted entity cache immediately in core after saving or updating.

@philsward
Copy link

I feel like the suggestion is the "expected" workflow, however...

Two thoughts:

  1. Smaller, low traffic sites, this workflow will be fine.

  2. Larger, high traffic sites, this might cause strain on the webserver and database, impacting performance.

I unfortunately don't have any suggestion for #2 other than a contrib giving explicit control over the workflow.

@indigoxela
Copy link
Member

Cache invalidation can be tricky. Clearing the whole cache doesn't seem the right approach, though. We should rather clear the specific caches, that are affected by a comment addition (or edit). Which ones?

Adding a comment might also affect a specific node and page cache entry - is that correct?

@laryn
Copy link
Contributor Author

laryn commented Oct 29, 2021

I think the command I listed will only clear a specific comment's cache, not all caches. It seems to be working in a module that I'm testing with.

cache_clear_all($comment->cid, 'cache_entity_comment');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants