Deprecate CacheBackendInterface::invalidateAll()

Created on 11 January 2025, 2 months ago

Problem/Motivation

We have exactly one valid use case for invalidating a specific item in core vs delete (CacheCollector), but I don't see a use case for invalidateAll(). There is \Drupal\system\Entity\Menu::save(), but IMHO, it's mostly a naming problem because you invalidate the cache. But really you should use deleteAll() in that case IMHO, which actually deletes the entries (in the database implementation. redis is another special thing).

Quite a lot of calls in contrib (https://git.drupalcode.org/search?group_id=2&scope=blobs&search=%22-%3Ei...), most of those are just flat out wrong (cache.render invalidate all should really invalidate the rendered cache tag, that won't work for page cache and dynamic page cache)

Reason: It's an expensive thing for redis and I guess also memcache to support, because redis implements it as an extra cache tag. See πŸ“Œ Optimize bin cache tags and last write timetamp Active as a related issue.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

cache system

Created by

πŸ‡¨πŸ‡­Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @berdir
  • Merge request !10876deprecate invalidateAll() β†’ (Closed) created by berdir
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Created a basic merge request, will need an update with the change record if others agree.

  • Pipeline finished with Failed
    2 months ago
    Total: 99s
    #393158
  • Pipeline finished with Running
    2 months ago
    #393184
  • Pipeline finished with Failed
    2 months ago
    Total: 103s
    #393452
  • Pipeline finished with Failed
    2 months ago
    Total: 505s
    #393477
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Can we add a CR for the deprecations and update the messages to use that link vs the issue. Since there is a replacement I'm a big fan of before/after snippets

  • Pipeline finished with Failed
    about 2 months ago
    Total: 185s
    #399173
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    I tend to start off without to get early feedback. But I'm also aware that helps with explaining the reason, created one now.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 6389s
    #399675
  • Pipeline finished with Success
    about 2 months ago
    Total: 513s
    #400314
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Per slack this is fine to remove.

    Just fyi wasn't against it or anything just didn't think I could make the call around it but @catch was kind enough to approve.

    Verified the CR reads well, thanks for the before/after snippets.

    Don't see anything else to review.

  • πŸ‡¬πŸ‡§United Kingdom oily Greater London

    I agree with #6 that the CR is quite readable. But perhaps like Hayden would perfectly understand Mozart's explanation of a passage, the CR is a IMO a little hard to grasp for an average musician.

    I have edited it and tried to put it in terms that I understand which has the advantage of showing what I am not grasping. Using the supermarket shelf analogy, I am unsure about what happens when the item is deleted (incinerated). It seems that with Redis etc a label is placed on the shelf stating 'this item has been incinerated'? Not sure about Drupal standard caching, though.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    I'm not sure how detailed the change record needs to explain invalidate vs delete. This doesn't change the concept of invalidation or remove it, it only removes the ability to invalidate a whole bin. deleteAll() in redis has exactly the same problem as invalidateAll(), it also doesn't actually delete anything and just sets a timestamp. With redis, deleteAll() doesn't mean that cache items cease to exist.

    That said, I wrote a long blog post about the background and details around some of my recent performance improvements: https://www.md-systems.ch/en/blog/2025-01-26/redis-startup-performance-i...

  • πŸ‡¬πŸ‡§United Kingdom oily Greater London

    @berdir Ah, interesting it's even more complicated than i thought. Perhaps including the link would help.

    it only removes the ability to invalidate a whole bin

    That seems a really important point at least for my personal understanding.

    deleteAll() in redis has exactly the same problem as invalidateAll(), it also doesn't actually delete anything and just sets a timestamp

    Okay but this issue does not make any difference to that Redis problem? It is a Redis problem that is much harder to deal with? Even though the nature of the problem is very similar.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    The difference is that deleteAll() is needed. We need a way to completely delete all entries in a bin. What we IMHO don't need is two different ways of doing that. As I wrote in my blog post, you should only use invalidate* methods when you have a specific use case and might want to later on fetch invalidated items again. For anything else, use delete*() methods.

    Then redis only needs to handle one all method and not two that vary and therefore require a different implementation and different check.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Needs a rebase.

  • πŸ‡¬πŸ‡§United Kingdom catch

    gitlab MR rebase was enough.

    Committed/pushed to 11.x, thanks!

    • catch β†’ committed 66dd103a on 11.x
      Issue #3498947 by berdir, smustgrave: Deprecate CacheBackendInterface::...
  • Pipeline finished with Success
    about 1 month ago
    Total: 384s
    #413503
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024