mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Cache namespace from Setup::createCacheConfiguration gets lost #6782
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @flack on GitHub (Jul 6, 2021).
BC Break Report
Summary
I'm running multiple independent websites on the same server. They all use Doctrine and share the same Memcache instance for ClassMetadata cache. In some cases, the sites use the same entity classnames, but with different fields.
Previous behavior
Until now, everything was working fine, because each site uses a separate proxy dir, and the proxy dir is used as a namespace in the cache setup:
3c805b22b4/lib/Doctrine/ORM/Tools/Setup.php (L172)If I called
dump($em->getConfiguration()->getMetadataCacheImpl());on doctrine/orm 2.8, I would get the following output:Current behavior
The same call to
dump($em->getConfiguration()->getMetadataCacheImpl());on doctrine/orm 2.9 prints the following output:The visible problem is that now only one of my sites is working, the other one gets wrong ClassMetadata information and then prints various errors. When I clear the cache, then this site starts working and the other one is throwing errors, because they overwrite each other's cache entries
I'm not exactly sure where it happens, but the first place I noticed the namespace getting lost is in the
CacheAdapter::wraphere:3c805b22b4/lib/Doctrine/ORM/Tools/Setup.php (L144)if I
dump($cache->getPool(), $cache)in line 39 of doctrine/cache/lib/Doctrine/Common/Cache/Psr6/CacheAdapter.php it looks like this:so the namespace information is available on the
$cacheobject, but not on the inner pool variable.How to reproduce
In principle it should be enough to create a connection and an EntityManager:
@flack commented on GitHub (Jul 7, 2021):
Here's a minimal diff that seems to fix the problem for me:
@stof commented on GitHub (Jul 7, 2021):
Having the namespace being set in the DoctrineProvider object is the expected behavior. This will apply the namespace to the id before asking the PSR-6 cache to get it.
The fact that the symfony/cache adapter has its own concept of namespacing is totally independent (and irrelevant in that case).
@flack commented on GitHub (Jul 7, 2021):
@stof well, the namespace might be set on the DoctrineProvider, but it gets lost during
$config->setMetadataCache(CacheAdapter::wrap($cache));(becausewrapreturns the inner pool object, which doesn't have the namespace info). So effectively, all sites on the same machine share the same (empty) cache namespace for ClassMetadata, which wasn't the case in previous versions.@stof commented on GitHub (Jul 7, 2021):
@alcaeus this might be a flaw of the PSR-6 migration layer than, that does not account for namespaces.
@stof commented on GitHub (Jul 7, 2021):
then,
Setup::createCacheConfigurationin the ORM might want to put the namespace in the symfony/cache pool instead of the doctrine/cache object when using symfony/cache as the storage (to put the namespace on the actual storage rather than a compat adapter)@flack commented on GitHub (Jul 7, 2021):
in case it helps, here's a simple reproducer script (add db config as necessary):
@stof commented on GitHub (Jul 19, 2021):
@greg0ire this one is not fixed by the doctrine/cache change. The bug does not appear anymore thanks to the doctrine/cache fix, but the Setup tools should still be updated to use a symfony/cache namespacing instead of a doctrine/cache one when it instantiates a symfony cache, to avoid a hard dependency on doctrine/cache forever.
@alcaeus commented on GitHub (Jul 19, 2021):
IIRC, the setup tool is considered deprecated, which is why I only "made it work". If we want to keep it around for 3.0, it makes sense to create issues for improvements so people can work on them independently.