Skip to content

Conversation

@vidarl
Copy link
Member

@vidarl vidarl commented Nov 2, 2017

Issue: https://jira.ez.no/browse/EZEE-1780

This PR makes it possible to extend http cache in 3rd party bundles

Depends on:

ezplatform.view_cache.response_tagger.restlocationbc:
class: EzSystems\PlatformHttpCacheBundle\ResponseTagger\Value\RestLocationBCTagger
tags:
- {name: ezplatform.cache_response_tagger}
Copy link
Member Author

@vidarl vidarl Nov 2, 2017

Choose a reason for hiding this comment

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

@bdunogier :
I really don't get the reasoning behind splitting the response taggers in delegators and values. It just creates overhead? Also, given that we keep this split, why does also the value tagges have the ezplatform.cache_response_tagger tag? It means they are invoked both by the dispatcher directly, and by their deligator

$view = $event->getRequest()->attributes->get('view');
if (!$view instanceof CachableView || !$view->isCacheEnabled()) {
return;
if ($event->getRequest()->attributes->has('is_rest_request') && $event->getRequest()->attributes->get('is_rest_request') === true) {
Copy link
Contributor

@andrerom andrerom Nov 5, 2017

Choose a reason for hiding this comment

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

Maybe this subscriber needs a new name, but this subscriber to me is for ContentView.

Not all rest requests are supposed to be cacheable afaik, so if (we make it) expose RestValue or something on Response (is it maybe still on the getControllerResult?), then we can have a dedicated subscriber for rest responses.

Copy link
Contributor

Choose a reason for hiding this comment

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

see #25 I would think this part is not needed anymore if we handle X-Location-Id issue in separate listener

Copy link
Contributor

@Plopix Plopix Nov 8, 2017

Choose a reason for hiding this comment

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

+1 on @andrerom comment

{
// Rest API sets the X-Location-Id header. This needs to be changed according to http cache in use
if ($value === null && $response->headers->has('X-Location-Id')) {
$this->restLocationBCTagger->tag($configurator, $response, ['X-Location-Id' => $response->headers->get('X-Location-Id')]);
Copy link
Contributor

@andrerom andrerom Nov 5, 2017

Choose a reason for hiding this comment

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

Kind of duplicates #21

And it seems a bit strange to use several layers of response taggers to map X-Location-id to xkey and remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

and now it is also useless because of #25 I think

/**
* Purge client based on FOSHttpCacheBundle.
*
* Only support BAN requests on purpose, to be able to invalidate cache for a
Copy link
Contributor

Choose a reason for hiding this comment

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

BAN not updated right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, that was an old comment... Removed it

// eZ\Publish\Core\MVC\Symfony\Cache\Http\FOSPurgeClient
// Or else, that deprecated class is still used by cache:clear
if ($purgeType !== 'local') {
$container->setAlias('ezpublish.http_cache.purge_client', $purgeServiceId);
Copy link
Contributor

@Plopix Plopix Nov 5, 2017

Choose a reason for hiding this comment

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

should use ezplatform.http_cache.purge_client I think because this bundle is overriding it
See other bug

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I meant what I wrote here....
This line ensured that correct purge client was used when running php app/console clear:cache

However, it seems like it was decided in #15 that we should not clear http cache when doing a clear cache

So, if #15 stays, this line can be removed

Copy link
Contributor

@andrerom andrerom Nov 6, 2017

Choose a reason for hiding this comment

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

15 was not necessarily the final say on it, it was to solve a bug where kernel purge system will be called on cache:clear, when if we need such logic should have the proper config for it here.

But we don't clear Stash / Symfony cache either on cache:clear by default (unless file system cache is used), but it should be possible somehow to do it when content or schema for some reason changes on deployment. If so, purge for symfony cache, and expire (soft purge) for http cache.

Copy link
Contributor

Choose a reason for hiding this comment

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

But this line can indeed be removed, ca:cl is not supposed to call kernel purge client anymore with this bundle enabled. Actually almost all http cache code in kernel is deprecated in favor of this bundle.

Copy link
Contributor

@Plopix Plopix Nov 6, 2017

Choose a reason for hiding this comment

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

in any case are we sure we don't want to use ezplatform.http_cache.purge_client and not ezpublish.http_cache.purge_client one is meant to replace the other right ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think I understood your last comment, but I have removed the line in question as it does not do anything after #15 was merged

{
public function process(ContainerBuilder $container)
{
$purgeType = $container->getParameter('purge_type');
Copy link
Contributor

@Plopix Plopix Nov 5, 2017

Choose a reason for hiding this comment

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

we should not use the parameter here... that could be renamed. we should use the ezpublish.http_cache.purge_type settings

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm.. Not sure that is possible in a compiler pass. You know how?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not by default, I think, no way :( But for sure we should do that on purge_type.

You will have to set the value as a parameter here:
https://github.com/ezsystems/ezpublish-kernel/blob/master/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/EzPublishCoreExtension.php#L392

$container->setParameter("ezpublish.http_cache.purge_type", $config['http_cache']['purge_type']);

And then refer to it

$purgeType = $container->getParameter('ezpublish.http_cache.purge_type');

Then comes the SiteAccess Awareness, but I think that is global then a parameter would be fine.

@andrerom @bdunogier another idea?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, fixed as suggested

@vidarl vidarl changed the title Plugin support WIP Plugin support Nov 8, 2017
@vidarl vidarl changed the title WIP Plugin support [WIP] Plugin support Nov 8, 2017
@vidarl vidarl force-pushed the plugin_support branch 3 times, most recently from a3e83d7 to 5702f5f Compare November 15, 2017 11:04
@vidarl vidarl changed the title [WIP] Plugin support Plugin support Nov 15, 2017
* Triggers the cache purge $locationIds.
* Triggers the cache purge of $tags.
*
* It's up to the implementor to decide whether to purge $locationIds right away or to delegate to a separate process.
Copy link
Contributor

Choose a reason for hiding this comment

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

$locationIds

Copy link
Member Author

@vidarl vidarl Nov 15, 2017

Choose a reason for hiding this comment

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

So you insist on calling it $locationIds ?
It is not consistent with https://github.com/ezsystems/ezplatform-http-cache/pull/19/files#diff-cdb40d122691729c63752db68cddf3f9R31 and other places
And besides, there are not only location ids, also path-XX, content-XX and content-type-XX etc.....

Copy link
Contributor

@andrerom andrerom Nov 15, 2017

Choose a reason for hiding this comment

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

No, you misunderstand me. I was referring to text here mentioning $locationIds when it should be aligned with the other changes you make to refer to tags instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah... missed that one.. will fix

Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

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

+1, but I guess this depends on kernel changes

so:

  • I'll ping you on that separately
  • Requirement for kernel should then be bumped here in this PR to:
    "ezsystems/ezpublish-kernel": "~6.7.7@dev || ^6.12.1@dev || ^7.0@dev"

Copy link

@DominikaK DominikaK left a comment

Choose a reason for hiding this comment

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

A few language nitpicks in the doc.

docs/drivers.md Outdated
- TagHandler
- FOS TagHandler

If you write a new PurgeClient driver, you **must** also create a corresponding TagHandler and vise

Choose a reason for hiding this comment

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

...TagHandler and vice

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

docs/drivers.md Outdated

The PurgeClient is responsible for sending purge requests to the http cache when content is about to be invalidated.
The PurgeClient must implement EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface and can be registered
with the following code in service.yml:

Choose a reason for hiding this comment

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

Isn't it serviceS.yml?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it is. good catch....

docs/drivers.md Outdated

## FOS TagHandler

The FOS Http cache bundle also have a TagHandler which is not used by eZ Platform except for one thing, the

Choose a reason for hiding this comment

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

...also has a TagHandler...

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

docs/drivers.md Outdated
## FOS TagHandler

The FOS Http cache bundle also have a TagHandler which is not used by eZ Platform except for one thing, the
`fos:httpcache:invalidate:tag` command. With this command you may explicit invalidate cache by tag.

Choose a reason for hiding this comment

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

...you may explicitly invalidate cache...

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

docs/drivers.md Outdated

Normally, you would not need to implement your own FOS TagHandler as the ezplatform-http-cache bundle ships with a
default one which uses the PurgeClient to invalidate the given tags.
If you anyway need to write your own FOS TagHandler, you may register it with the following code in service.yml:

Choose a reason for hiding this comment

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

If you need to write your own FOS TagHandler anyway...

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed


public function getAlias()
{
return 'ez_platform_cache';
Copy link
Contributor

Choose a reason for hiding this comment

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

ez_platform_http_cache, method can afaik be avoided by renaming this class to EzPlatformHttpCacheExtension which getContainerExtension() will then need to be adapted for.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that will be better. If I rename class, then I think the most clean way should be to also override Bundle::getContainerExtensionClass() ( and not write logic concerning class name in getContainerExtension() ).

So IMO it is either to create a getAlias() or a getContainerExtensionClass() method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced getAlias() with getContainerExtensionClass()

composer.json Outdated
"minimum-stability": "stable",
"require": {
"ezsystems/ezpublish-kernel": "^6.7@dev || ^7.0@dev",
"ezsystems/ezpublish-kernel": "~6.7.7 || ^6.12.1 || ^7.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

you'll need to keep dev for tests to continue to work

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed in 358a682

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed again in b8a2348

please pull in changes before rebasing ;)

@andrerom andrerom requested a review from alongosz November 16, 2017 18:05
@andrerom andrerom changed the title Plugin support EZEE-1780: Plugin support Nov 17, 2017
docs/drivers.md Outdated
services:
ezplatform.http_cache_myhttpcachebundle.purge_client.myhttpcache:
class: EzSystems\PlatformMyHttpCacheBundle\PurgeClient\MyHttpCachePurgeClient
arguments: ["@ezplatform.http_cache.cache_manager"]
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Let's advocate in doc single quotes as well here. Sorry to be persistent and boring, just trying to clean the mess I made some time ago ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

no reason to apologize. I guess I should use single quotes in the actuall services.yml to then... Will fix

if ($this->extension) {
return $this->extension;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we just return new EzPlatformHttpCacheExtension()? See Symfony doc

Copy link
Member Author

Choose a reason for hiding this comment

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

ah.... man.... This we talked about yesterday
Ok, I'll change it again

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I think I missed the point of that discussion and didn't see this code yesterday. Doing too many things at the same time ;)

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class DriverPass implements CompilerPassInterface
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Please add brief description on what this Compiler Pass does.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@andrerom andrerom merged commit 750407d into ezsystems:master Nov 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants