Cache bin names should be set from service tags, not the service name

Created on 28 March 2022, about 2 years ago
Updated 30 May 2024, 26 days ago

Problem/Motivation

Cache bin service naming is hardwired in Drupal and ListCacheBinsPass classes. This is weird and highly unusual, might be called an antipattern.

Also, RenderCache presumes every cache bin service is defined with factory: ['@cache_factory', 'get'].

Steps to reproduce

Proposed resolution

  1. Add the name of the bin to the cache.bin tag. This makes it possible to drop any presumptions on the service naming.
  2. Add a cache_factory_delegated service which allows getting any cache service. Drupal::cache becomes return static::getContainer()->get('cache_factory_delegated')->get($bin);. RenderCache similarly.

The necessary code is minimal because ListCacheBinsPass already exists. Not counting the BC layer, it requires three new lines of code there. The new DelegatedCacheFactory contains a single line of code of logic the rest is comments etc.

Remaining tasks

Review.

User interface changes

None.

API changes

Cache bins must now include a bin specified in the service tag.

Data model changes

None.

Release notes snippet

CR drafted.

πŸ› Bug report
Status

Needs review

Version

11.0 πŸ”₯

Component
CacheΒ  β†’

Last updated about 9 hours ago

Created by

πŸ‡¨πŸ‡¦Canada Charlie ChX Negyesi 🍁Canada

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Merge request !8060Rebase on to 11.x β†’ (Open) created by bradjones1
  • Pipeline finished with Failed
    about 1 month ago
    Total: 142s
    #172129
  • Pipeline finished with Failed
    about 1 month ago
    Total: 180s
    #172152
  • Pipeline finished with Failed
    about 1 month ago
    Total: 177s
    #172167
  • Pipeline finished with Failed
    about 1 month ago
    Total: 528s
    #172168
  • Status changed to Needs review about 1 month ago
  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

    Rebased this into an MR.

    Variationcache went into core since this was first rolled so that affected a few things, but nothing too bad. It seems like we're collecting memory caches into a new container parameter now for... some reason that is not really clear to me other than parity with prior behavior.

    It seemed to me that we also need to explicitly guard against name conflicts in cache bins because we can no longer rely on the service container doing so. This is actually an improvement in DX, I think, since these will now be explicitly caught instead of silently kludged. (Since later service definitions overwrite earlier ones during builds.) I don't think this is a BC issue per se but it might be worth a CR.

    Improved the test coverage of this as well.

  • Pipeline finished with Failed
    about 1 month ago
    #172185
  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life
  • Pipeline finished with Success
    about 1 month ago
    Total: 575s
    #172197
  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life
  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life
  • Pipeline finished with Success
    about 1 month ago
    Total: 556s
    #172702
  • πŸ‡¨πŸ‡¦Canada Charlie ChX Negyesi 🍁Canada

    https://www.drupal.org/project/drupal/issues/3272093#comment-14642054 πŸ› Cache bin names should be set from service tags, not the service name Needs review was RTBC but there was a complaint about how it always instantiated the service. It's possible this was not solvable at the time but now we have ServiceClosureArgument and I am 99% it is a perfect replacement for Reference here. So $factory->addMethodCall('offsetSet', [$bin, new ServiceClosureArgument($id)]); and then return $this->offsetGet($bin)();.

  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

    Updated this per the feedback in #60.

  • Pipeline finished with Success
    about 1 month ago
    Total: 699s
    #172771
  • Pipeline finished with Success
    about 1 month ago
    Total: 1784s
    #172819
  • Merge request !820110.x version - for tests and comparison β†’ (Closed) created by bradjones1
  • Pipeline finished with Failed
    28 days ago
    #183729
  • Pipeline finished with Failed
    28 days ago
    Total: 184s
    #183737
  • Status changed to Needs work 28 days ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

    bradjones1 β†’ changed the visibility of the branch 3272093-remove-hardwired-assumptions-10.x to hidden.

  • Status changed to Needs review 28 days ago
  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

    I think the bot was confused by my uploading a 10.2.x branch for comparison (and for anyone wanting to apply this on to a 10.x project...) I rebased the 11.x branch and it still applies cleanly so this is back to NR.

  • Pipeline finished with Success
    28 days ago
    Total: 623s
    #184314
  • Pipeline finished with Failed
    28 days ago
    Total: 511s
    #184324
  • Status changed to Needs work 28 days ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review 28 days ago
  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Should we be aiming to use the service locator pattern for the final solution here?

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Heavy +1 from me. Recently had a presentation on VariationCache and felt stupid for having to emphasize that people had to name their caches "cache.foo" because reasons.

  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

    Re: #70 I'm not sure if a service locator is currently supported in the Drupal DI container? Even if it is, @chx recommended service closures which I think are pretty elegant and the Symfony docs suggest that as a valid way to do lazy-ish instantiation which is what we're doing here. I don't personally see a reason to change it.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    We are already using service locators in core:

    • RegisterAccessChecksPass
    • RegisterStreamWrappersPass

    Not picking sides, just stating facts.

Production build 0.69.0 2024