cache.backend.chainedfast misbehaves when both fast and consistent backends point to the same storage

Created on 4 February 2016, almost 9 years ago
Updated 20 February 2023, over 1 year ago

Problem/Motivation

cache.backend.chainedfast doesn't like it if the fast and persistent backend is set to the same thing.

This is unsupported so we can't make it 'work'.

Steps to reproduce:

1. Append to your services.yml:

services:
  cache.backend.chainedfast:
    class: Drupal\Core\Cache\ChainedFastBackendFactory
    arguments: ['@settings', 'cache.backend.database', 'cache.backend.database']
    calls:
      - [setContainer, ['@service_container']]

2. drush cr --yes
3. Enable aggregator module.
4. You get a undefined entity exception

Proposed resolution

Originally, the patch triggered an error when this configuration was found, but this is too low level to be safe - see comments from @chx.

The new approach in the MR detects this case and only sets the persistent backend, leaving the fast backend unset, so this will 'silently work'.

Remaining tasks

Add test coverage if possible.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Fixed

Version

10.1

Component
Cache 

Last updated about 4 hours ago

Created by

🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

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

Comments & Activities

Not all content is available!

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

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    Think the issue summary needs an update.

    Research why this happens and fix.

    What was found and how was it fixed?

  • 🇬🇧United Kingdom catch

    The approach in the merge request looks OK to me, but none of the previous attempts at test coverage will be relevant with that approach.

  • 🇮🇳India Yogesh Sahu

    Attached patch against Drupal 10.1.x

  • 🇨🇦Canada gapple

    @Yogesh Sahu, your patch looks like it's done a PSR-2 reformatting of the entire file, and it's unclear what changes your patch is based on.

  • Status changed to Needs review over 1 year ago
  • 🇨🇦Canada gapple

    Rebased the MR, and added tests for the ChainedFastBackendFactory class.

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    Seems close to ready just some CI failures in the MR

  • Status changed to Needs review over 1 year ago
  • 🇨🇦Canada gapple

    Hopefully just the quick fix to pass spellcheck

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    Removing issue summary update as that looks completed in #59

    When I ran the tests locally without the fix

    testIdenticalService failed with "Symfony\Component\DependencyInjection\ContainerInterface::get('cache.backend.test', 1): object was not expected to be called more than once." = GOOD

    testDifferentServices = Passed.

    Shouldn't both tests fail?

    If I got that wrong then think this is good to be marked RTBC

  • Status changed to RTBC over 1 year ago
  • 🇨🇦Canada gapple

    testDifferentServices() uses the correct way to instantiate the factory, so should pass both before and after.

    • catch committed 91247936 on 10.1.x
      Issue #2662844 by gapple, yogeshmpawar, penyaskito, dawehner, catch,...
  • Status changed to Fixed over 1 year ago
  • 🇬🇧United Kingdom catch

    Committed 9124793 and pushed to 10.1.x. Thanks!

Production build 0.71.5 2024