Skip to content

[Doctrine][4.4] Documentation not clear about how to use "metadata_cache_driver" (May result in Unknown cache of type "array" configured for cache "metadata_cache" in entity manager "default".) #12788

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

Closed
k00ni opened this issue Dec 9, 2019 · 5 comments
Labels

Comments

@k00ni
Copy link

k00ni commented Dec 9, 2019

On the Doctrine configuration page (https://symfony.com/doc/4.4/reference/configuration/doctrine.html) it states to use the following configuration to setup Doctrine:

doctrine:
    orm:
        auto_mapping: true
        # the standard distribution overrides this to be true in debug, false otherwise
        auto_generate_proxy_classes: false
        proxy_namespace: Proxies
        proxy_dir: '%kernel.cache_dir%/doctrine/orm/Proxies'
        default_entity_manager: default
        metadata_cache_driver: array
        query_cache_driver: array
        result_cache_driver: array

But when using it, i get the following error:

Unknown cache of type "array" configured for cache "metadata_cache" in entity manager "default".

Here is my configuration:

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_520_ci

        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_mapping: true
        # the standard distribution overrides this to be true in debug, false otherwise
        auto_generate_proxy_classes: false
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        metadata_cache_driver: array
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/App/Entity'
                prefix: 'App\Entity'
                alias: App

About my setup:

  • PHP 7.3
  • Symfony 4.4.1
  • Doctrine 2.7.0
  • Symfony ORM Pack 1.0.7

I also tried #10797, but it didn't help. Using metadata_cache_driver in doctrine.orm results in:

Symfony\Component\Config\Definition\Exception\InvalidConfigurationException: Unrecognized options "metadata_cache_driver, query_cache_driver, result_cache_driver" under "doctrine.orm". Available options are "auto_generate_proxy_classes", "default_entity_manager", "entity_managers", "proxy_dir", "proxy_namespace", "resolve_target_entities".


Did i missed something in the documentation?


EDIT: When running in dev environment, i had no problems, but after i started with PHPUnit tests requiring Doctrine, i ran into the error above.

@k00ni k00ni changed the title [Doctrine] Documentation not clear about how to use "metadata_cache_driver" (May result in Unknown cache of type "array" configured for cache "metadata_cache" in entity manager "default".) [Doctrine][4.4] Documentation not clear about how to use "metadata_cache_driver" (May result in Unknown cache of type "array" configured for cache "metadata_cache" in entity manager "default".) Dec 9, 2019
@k00ni
Copy link
Author

k00ni commented Dec 9, 2019

If i understand the related DoctrineExtension class right, it seems that you can't use an array:

<?php
// ...
// around line 723

    switch ($cacheDriver['type'] ?? 'pool') {
        case 'service':
            $serviceId = $cacheDriver['id'];
            break;
        case 'pool':
            $serviceId = $this->createPoolCacheDefinition($container, $cacheDriver['pool'] ?? $this->createArrayAdapterCachePool($container, $objectManagerName, $cacheName));
            break;
        case 'provider':
            $serviceId = sprintf('doctrine_cache.providers.%s', $cacheDriver['cache_provider']);
            break;
        default:
            throw new \InvalidArgumentException(sprintf(
                    'Unknown cache of type "%s" configured for cache "%s" in entity manager "%s".',
                    $cacheDriver['type'],
                    $cacheName,
                    $objectManagerName
            ));
    }
?>

Source: https://github.com/doctrine/DoctrineBundle/blob/2.0.x/DependencyInjection/DoctrineExtension.php#L716

@k00ni
Copy link
Author

k00ni commented Dec 10, 2019

Possible solution?

As described here, one just has to install

composer require symfony/proxy-manager-bridge

to solve the problem. Dont forget to clear your cache folder before trying it out!

As mentioned before, with dev environment i had no problems, they started arising when running test environment with PHPUnit bridge.

It worked for me together with the following changes:

config/doctrine.yaml

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        url: '%env(resolve:DATABASE_URL)%'
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_520_ci

    orm:
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_generate_proxy_classes: false
        metadata_cache_driver: #                <=== new
            type: service
            id: doctrine.system_cache_provider
        query_cache_driver: #                <=== new
            type: service
            id: doctrine.system_cache_provider
        result_cache_driver: #                <=== new
            type: service
            id: doctrine.result_cache_provider
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/App/Entity'
                prefix: 'App\Entity'
                alias: App

config/services.yaml

services:
    # ...
    doctrine.result_cache_provider: #        <==== new
        class: Symfony\Component\Cache\DoctrineProvider
        public: false
        arguments:
            - '@doctrine.result_cache_pool'
    doctrine.system_cache_provider: #        <==== new
        class: Symfony\Component\Cache\DoctrineProvider
        public: false
        arguments:
            - '@doctrine.system_cache_pool'

config/framework.yaml

framework:
    cache:
        # ....
        pools: #        <==== new
            doctrine.result_cache_pool:
                adapter: cache.app
            doctrine.system_cache_pool:
                adapter: cache.system

Can someone tell me, why i have to install symfony/proxy-manager-bridge here?

Shouldn't these information be added to the documentation? What do you think?

@k00ni
Copy link
Author

k00ni commented Feb 18, 2020

Any feedback on this please?

@flaushi
Copy link

flaushi commented Feb 23, 2020

I understand the docs in such a way that your solution of defining a service per cache pool is equivalent to configuring

orm:
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_generate_proxy_classes: false
        metadata_cache_driver: #                <=== new
            type: pool     <=== changed
            id: doctrine.system_cache_pool<=== changed
        query_cache_driver: #                <=== new
            type: pool
            id: doctrine.system_cache_pool
        result_cache_driver: #                <=== new
            type: pool
            id: doctrine.result_cache_pool

and omitting the service definition.
But:

  • Your solution (with service definition) works, but some apis do not function correctly, e.g. bin/console doctrine:cache:clear-metadata has no effect.
  • The solution without service just doesn't work for me, effectively I think only an array cache is in use (the snippet you posted above also indicates that in the else-part)

@carsonbot
Copy link
Collaborator

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

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

No branches or pull requests

3 participants