Skip to content
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

Add configless metadata caching #685

Closed

Conversation

Ahummeling
Copy link
Contributor

Quoting @alcaeus description of the related PR #675

This PR deprecates the metadata_cache_driver config key in favour of automatic configuration. In debug mode, it creates an ArrayAdapter, meaning that the cache is only valid per request. This is usually desired in a development environment. When debug is disabled, it creates a PhpArrayAdapter, backed by an array cache. The cache is warmed up and stored in the file system. Since this information shouldn't be shared between multiple instances of the code, it is only logical to store this in the cache folder in an efficient format. This also mirrors a decision made in the ORM bundle to deprecate the config.

Comment on lines +535 to +547
// Convert to PSR-6 cache if required
$cacheServiceId = $this->getObjectManagerElementName($documentManager['name'] . '_metadata_cache');
$cacheDefinition = $container->getDefinition($cacheServiceId);
if (is_a($cacheDefinition->getClass(), CacheItemPoolInterface::class, true)) {
return;
}

$adapterDefinition = new Definition(CacheItemPoolInterface::class);
$adapterDefinition
->setFactory([CacheAdapter::class, 'wrap'])
->setArgument(0, $cacheDefinition);

$container->setDefinition($cacheServiceId, $adapterDefinition);
Copy link
Member

Choose a reason for hiding this comment

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

This part won't work like that, as we can't check the cache definitions class at this stage. In DoctrineBundle, we worked around this by adding a compiler pass that converts caches to the correct instance: https://github.com/doctrine/DoctrineBundle/blob/2.4.x/DependencyInjection/Compiler/CacheCompatibilityPass.php

ODM only has metadata caching, so we don't need to account for other caches like we do for ORM, but the logic can stay the same.

In the extension, we then set up the metadata cache layer the way it has been, with the compiler pass ensuring that the correct cache instance is passed to the configuration.

@Ahummeling
Copy link
Contributor Author

Implementing psr6 compatibility pass in this pr

@stale
Copy link

stale bot commented Sep 6, 2021

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Issues that have not seen any activity in 30 days label Sep 6, 2021
@stale stale bot closed this Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Issues that have not seen any activity in 30 days
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants