Fixed overwriting explicit cache namespace#5904
Conversation
| } | ||
|
|
||
| if ($cache instanceof CacheProvider) { | ||
| if ($cache instanceof CacheProvider && $cache->getNamespace() === '') { |
There was a problem hiding this comment.
(actually correct, since === '' is not needed.getNamespace() may return '0'. Tests required tho
There was a problem hiding this comment.
I think that we should use the same approach of L2C where we always change change the namespace but using the current namespace as prefix, like:
There was a problem hiding this comment.
not necessarily generating a new instance, though
6660481 to
0cfc222
Compare
|
Added tests. |
|
Hi there. Is there a way to upvote this Pull Request to be accepted? We're facing the same issue, but it has more dramatic impact for us. We use Doctrine for two separate application. These applications have shared Memcache cluster and same So, as you may already guess, well you clear metadata cache from one application, actually another application's metadata cache is cleared as well. And, as soon as any application regenerates it's metadata cache, the other application becomes broken, because cached metadata does not match actual entities and source metadata. |
|
Overriding the namespace is very confusing. And breaks the initial purpose of that - keeping more than one application separated from each other. Thanks |
lcobucci
left a comment
There was a problem hiding this comment.
The general idea LGTM to me, I'll be applying some changes to get this merged ASAP!
| $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\YamlDriver', $config->getMetadataDriverImpl()); | ||
| } | ||
|
|
||
| public function testConfigureCacheNamespace() |
| // automatically set namespace | ||
| $config = Setup::createConfiguration(false, '/foo'); | ||
|
|
||
| $this->assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $config->getMetadataCacheImpl()->getNamespace()); |
There was a problem hiding this comment.
self::assert* is preferable since the method is static
| $cache->setNamespace('foo'); | ||
| $config = Setup::createConfiguration(false, '/foo', $cache); | ||
|
|
||
| $this->assertSame('foo', $config->getMetadataCacheImpl()->getNamespace()); |
There was a problem hiding this comment.
self::assert* is preferable since the method is static
|
|
||
|
|
||
| // manually set namespace | ||
| $cache = new ArrayCache(); |
There was a problem hiding this comment.
It would be better if we move this to another test case, to make things more explicit
@thekia19 this is a generic way to setup the ORM, you can (and should IMO) create the configuration object by yourself and fine tune things the way you need. I'd say that we should override the namespace to avoid conflicts but the original namespace MUST be considered. |
Fix overwriting explicit cache namespace Replaces: #5904
Backporting: doctrine#6848 Backporting: doctrine#5904
|
@JanJakes 🚢 and backported to 2.5! Thanks for your contribution |
|
@lcobucci Thanks! |
When trying to use explicit namespace revision (i.e. revision as cache namespace:
$cache->setNamespace($revision)), Doctrine overwrites the revision by some default namespace derived from proxy dir (which in environments like Docker does not differ from revision to revision).