Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixed overwriting explicit cache namespace#5904

Closed
JanJakes wants to merge 1 commit into
doctrine:masterfrom
JanJakes:cache-namespace-fix
Closed

Fixed overwriting explicit cache namespace#5904
JanJakes wants to merge 1 commit into
doctrine:masterfrom
JanJakes:cache-namespace-fix

Conversation

@JanJakes
Copy link
Copy Markdown

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).

}

if ($cache instanceof CacheProvider) {
if ($cache instanceof CacheProvider && $cache->getNamespace() === '') {
Copy link
Copy Markdown
Member

@Ocramius Ocramius Jun 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=== '' is not needed. (actually correct, since getNamespace() may return '0'. Tests required tho

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

https://github.com/doctrine/doctrine2/blob/b7cace86a078feb9d6da4f69fa4a49b99b353258/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php#L234-L251

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessarily generating a new instance, though

@JanJakes JanJakes force-pushed the cache-namespace-fix branch from 6660481 to 0cfc222 Compare March 20, 2017 12:37
@JanJakes
Copy link
Copy Markdown
Author

Added tests.

@dytyniuk
Copy link
Copy Markdown

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 proxyDir configuration value. Applications have several entities with same names, but totally different relations.

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.

@thekia19
Copy link
Copy Markdown

Overriding the namespace is very confusing. And breaks the initial purpose of that - keeping more than one application separated from each other.
Please take a look on pull request.

Thanks

Copy link
Copy Markdown
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: void missing

// automatically set namespace
$config = Setup::createConfiguration(false, '/foo');

$this->assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $config->getMetadataCacheImpl()->getNamespace());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self::assert* is preferable since the method is static

$cache->setNamespace('foo');
$config = Setup::createConfiguration(false, '/foo', $cache);

$this->assertSame('foo', $config->getMetadataCacheImpl()->getNamespace());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self::assert* is preferable since the method is static



// manually set namespace
$cache = new ArrayCache();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if we move this to another test case, to make things more explicit

@lcobucci lcobucci added this to the 2.5.13 milestone Nov 26, 2017
@lcobucci
Copy link
Copy Markdown
Member

lcobucci commented Nov 26, 2017

Overriding the namespace is very confusing. And breaks the initial purpose of that - keeping more than one application separated from each other.

@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.

@lcobucci lcobucci self-assigned this Nov 26, 2017
lcobucci added a commit that referenced this pull request Nov 26, 2017
Fix overwriting explicit cache namespace

Replaces: #5904
lcobucci added a commit to lcobucci/doctrine2 that referenced this pull request Nov 26, 2017
@lcobucci lcobucci closed this Nov 26, 2017
@lcobucci
Copy link
Copy Markdown
Member

@JanJakes 🚢 and backported to 2.5! Thanks for your contribution

@JanJakes
Copy link
Copy Markdown
Author

@lcobucci Thanks!

@JanJakes JanJakes deleted the cache-namespace-fix branch November 29, 2017 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants