-
-
Notifications
You must be signed in to change notification settings - Fork 932
Switch to the new Symfony cache infrastructure #577
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace ApiPlatform\Core\Tests\Symfony\Bridge\Bundle\DependencyInjection; | ||
|
||
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\ApiPlatformExtension; | ||
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; | ||
use Prophecy\Argument; | ||
use Symfony\Component\Config\Resource\ResourceInterface; | ||
use Symfony\Component\DependencyInjection\Alias; | ||
|
@@ -33,9 +34,10 @@ class ApiPlatformExtensionTest extends \PHPUnit_Framework_TestCase | |
'description' => 'description', | ||
], | ||
]; | ||
|
||
private $extension; | ||
|
||
public function setUp() | ||
protected function setUp() | ||
{ | ||
$this->extension = new ApiPlatformExtension(); | ||
} | ||
|
@@ -152,25 +154,6 @@ public function testEnableNelmioApiDoc() | |
$this->extension->load(array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['enable_nelmio_api_doc' => true]]), $containerBuilder); | ||
} | ||
|
||
public function testSetApcuMetadataCache() | ||
{ | ||
$containerBuilderProphecy = $this->getContainerBuilderProphecy(); | ||
$containerBuilderProphecy->setAlias('api_platform.metadata.resource.cache', 'api_platform.metadata.resource.cache.apcu')->shouldBeCalled(); | ||
$containerBuilderProphecy->setAlias('api_platform.metadata.resource.cache', 'api_platform.metadata.resource.cache.array')->shouldNotBeCalled(); | ||
$containerBuilderProphecy->setAlias('api_platform.metadata.property.cache', 'api_platform.metadata.property.cache.apcu')->shouldBeCalled(); | ||
$containerBuilderProphecy->setAlias('api_platform.metadata.property.cache', 'api_platform.metadata.property.cache.array')->shouldNotBeCalled(); | ||
$containerBuilderProphecy->has('api_platform.metadata.resource.cache.apcu')->willReturn(true)->shouldBeCalled(); | ||
$containerBuilderProphecy->has('api_platform.metadata.resource.cache.array')->shouldNotBeCalled(); | ||
$containerBuilderProphecy->has('api_platform.metadata.property.cache.apcu')->willReturn(true)->shouldBeCalled(); | ||
$containerBuilderProphecy->has('api_platform.metadata.property.cache.array')->shouldNotBeCalled(); | ||
$containerBuilder = $containerBuilderProphecy->reveal(); | ||
|
||
$this->extension->load(array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['metadata' => [ | ||
'resource' => ['cache' => 'api_platform.metadata.resource.cache.apcu'], | ||
'property' => ['cache' => 'api_platform.metadata.property.cache.apcu'], | ||
]]]), $containerBuilder); | ||
} | ||
|
||
private function getContainerBuilderProphecy() | ||
{ | ||
$definitionArgument = Argument::that(function ($argument) { | ||
|
@@ -179,7 +162,7 @@ private function getContainerBuilderProphecy() | |
|
||
$containerBuilderProphecy = $this->prophesize(ContainerBuilder::class); | ||
$containerBuilderProphecy->getParameter('kernel.bundles')->willReturn([ | ||
'DoctrineBundle' => 'Doctrine\Bundle\DoctrineBundle\DoctrineBundle', | ||
'DoctrineBundle' => DoctrineBundle::class, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are other places where this is not changed. Perhaps we should make this consistent... (and for NelmioApiDocBundle as well) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 should be changed everywhere to the class constant. |
||
])->shouldBeCalled(); | ||
|
||
$parameters = [ | ||
|
@@ -259,17 +242,15 @@ private function getContainerBuilderProphecy() | |
'api_platform.metadata.resource.metadata_factory.short_name', | ||
'api_platform.metadata.resource.metadata_factory.operation', | ||
'api_platform.metadata.resource.metadata_factory.cached', | ||
'api_platform.metadata.resource.cache.array', | ||
'api_platform.metadata.resource.cache.apcu', | ||
'api_platform.metadata.resource.cache', | ||
'api_platform.metadata.property.name_collection_factory.property_info', | ||
'api_platform.metadata.property.name_collection_factory.cached', | ||
'api_platform.metadata.property.metadata_factory.annotation', | ||
'api_platform.metadata.property.metadata_factory.property_info', | ||
'api_platform.metadata.property.metadata_factory.serializer', | ||
'api_platform.metadata.property.metadata_factory.validator', | ||
'api_platform.metadata.property.metadata_factory.cached', | ||
'api_platform.metadata.property.cache.array', | ||
'api_platform.metadata.property.cache.apcu', | ||
'api_platform.metadata.property.cache', | ||
'api_platform.negotiator', | ||
'api_platform.route_loader', | ||
'api_platform.router', | ||
|
@@ -328,17 +309,12 @@ private function getContainerBuilderProphecy() | |
$aliases = [ | ||
'api_platform.routing.resource_path_generator' => 'api_platform.routing.resource_path_generator.underscore', | ||
'api_platform.metadata.resource.name_collection_factory' => 'api_platform.metadata.resource.name_collection_factory.annotation', | ||
'api_platform.metadata.resource.cache' => 'api_platform.metadata.resource.cache.array', | ||
'api_platform.metadata.property.cache' => 'api_platform.metadata.property.cache.array', | ||
]; | ||
|
||
foreach ($aliases as $alias => $service) { | ||
$containerBuilderProphecy->setAlias($alias, $service)->shouldBeCalled(); | ||
} | ||
|
||
$containerBuilderProphecy->has('api_platform.metadata.resource.cache.array')->willReturn(true)->shouldBeCalled(); | ||
$containerBuilderProphecy->has('api_platform.metadata.property.cache.array')->willReturn(true)->shouldBeCalled(); | ||
|
||
return $containerBuilderProphecy; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pertaining to symfony/symfony#18667, should our cache be considered a "system" or "app" cache? What are the semantics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can leverage the "system" cache, but if my understanding of the code is correct, these will be used in the
dev
environment as well... (Still, we should be safe because of the nonce invalidation.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
system
is the right choice here (system
is for local cache, usually for metadata,app
is for distributed cache, usually for data).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the semantics should be that "app" refers to the user project (the app that the user builds).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@teohhanhui you can discuss that on the Symfony issue tracker but I doubt it is worth it, it would be a BC break to change that and it's not acceptable as 3.1 has been released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has nothing to do with Symfony. As far as Symfony is concerned, everything Symfony goes under the "system" cache pool.
In any case, I'm just trying to clarify the semantics, and my conclusion seems to be consistent with yours (at least in this case).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact this is a nothing to do "directly" with Symfony:
system
will store the cache on the server (using APC or a file)app
will store the cache on a cache server (like Redis or Memcache)system
is better suited for cache that do not need to be shared between servers (like metadata cache).