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

[RTM] Introduced auto cache tag invalidation on DCAs for better DX #1478

Merged
merged 4 commits into from
Jun 9, 2018
Merged

[RTM] Introduced auto cache tag invalidation on DCAs for better DX #1478

merged 4 commits into from
Jun 9, 2018

Conversation

Toflar
Copy link
Member

@Toflar Toflar commented Apr 13, 2018

Automatically invalidates DCA entries when users edit them in the back end.
For testing purposes I've added corresponding tags on the page response.

Depends on contao/manager-bundle#67 which itself depends on other PR's again. Leaving it here for reference and to be updated.

@Toflar Toflar changed the title [WIP] Introduced auto cache tag invalidation on DCAs for better DX [RFC] Introduced auto cache tag invalidation on DCAs for better DX Apr 26, 2018
@Toflar
Copy link
Member Author

Toflar commented Apr 26, 2018

ping @contao/developers

This is ready to be reviewed. The goal here is that we invalidate tags based on a scheme (contao.dca.<table>.<id>). We automatically tag all pages, modules, articles and content elements. This means, you can now configure page cache settings to e.g. 30 days (that's the max as of today, we might want to adjust that to allow higher values?) and when you edit this page in the backend or an article, module or content element that's output on that page, the cache entry automatically gets purged. That means no more manual cache deletion for the users, just cache the page for as long as you can and Contao will automatically purge it when needed 😀

@aschempp you might want to include the response tagger service on your abstract fragments PR 😎

@Toflar
Copy link
Member Author

Toflar commented Apr 26, 2018

Of course, still depends on contao/manager-bundle#67 which is ready to be merged though, so would be glad if that happens soon @leofeyer so we can continue the work on master 😄

@leofeyer
Copy link
Member

Shouldn't we also tag pages?

@leofeyer leofeyer added this to the 4.6.0 milestone Apr 27, 2018
@leofeyer
Copy link
Member

Ah, I see. It is done in the FrontendTemplate class instead of in the Page* classes.

@@ -389,6 +390,16 @@ private function setCacheHeaders(Response $response)
$response->setSharedMaxAge($objPage->cache);
}

// Tag response
if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger'))
Copy link
Member

Choose a reason for hiding this comment

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

I think this code does not belong here. We cannot not assume that the return value of FrontendTemplate::getResponse() is always a page, can we? The code should go into the PageRegular class IMHO.

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 think it's correct here. It's the old FrontenTemplate::output() that was only called once and sent the response to the browser. It's the same thing for getResponse() now and we also set all the other caching headers regarding the page here (like disabling if FE preview is active and stuff).

Copy link
Member

@leofeyer leofeyer Apr 27, 2018

Choose a reason for hiding this comment

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

The old output() method still exists and the getResponse() method is not its replacement! You might as well use a front end template for an API or ESI response, therefore we cannot be sure it is always a page.

Copy link
Member Author

Choose a reason for hiding this comment

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

So why are all the other caching headers set there?

Copy link
Member

@leofeyer leofeyer Apr 27, 2018

Choose a reason for hiding this comment

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

Is this a serious question? An API or ESI response can have cache headers, which does not make it a page.

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course it's a serious question, I don't have time for non-serious questions. ESI requests should certainly not use FrontendTemplate::getResponse(). It would set caching headers from the page configuration which makes no sense. An ESI fragment should do exactly the opposite.

Copy link
Member

Choose a reason for hiding this comment

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

I'm using FrontendTemplate::getResponse a lot, so @leofeyer is right with his concern. Though it looks like the method is incorrect and should not add the page cache information…

Copy link
Member

Choose a reason for hiding this comment

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

It would set caching headers from the page configuration which makes no sense

That's true …

Copy link
Member Author

Choose a reason for hiding this comment

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

So I'm moving the relevant ones to PageRegular? Nobody can really re-use that but this concept has to be reworked for CMF routing anyway.

Copy link
Member

Choose a reason for hiding this comment

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

No, you don't have to move them. It is all based on $objPage, so either we change this or we might as well leave everything as it is.

*/
protected function getCacheTags($table, array $ids = array())
{
$ns = 'contao.dca.';
Copy link
Member

Choose a reason for hiding this comment

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

As discussed on the hackathon, we want to rename this to contao.db..

protected function getCacheTags($table, array $ids = array())
{
$ns = 'contao.dca.';
$table = preg_replace('/^tl_/', '', $table, 1);
Copy link
Member

Choose a reason for hiding this comment

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

As also discussed, we don't want to strip the tüdelü prefix.

@Toflar Toflar changed the title [RFC] Introduced auto cache tag invalidation on DCAs for better DX [RTM] Introduced auto cache tag invalidation on DCAs for better DX Jun 9, 2018
@Toflar
Copy link
Member Author

Toflar commented Jun 9, 2018

Updated according to latest discussions. This PR is RTM now imho.

@leofeyer leofeyer merged commit 60403e4 into contao:master Jun 9, 2018
@Toflar Toflar deleted the auto-dca-cache-tag-invalidation branch June 9, 2018 11:57
@leofeyer
Copy link
Member

leofeyer commented Jun 9, 2018

Thank you @Toflar.

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.

3 participants