eZ Community » Forums » Developer » [EZ 5] Problems with http cache and esi
expandshrink

[EZ 5] Problems with http cache and esi

[EZ 5] Problems with http cache and esi

Wednesday 06 August 2014 8:57:37 am - 2 replies

Hello there,

 

I've got a single page EZ 5 website (2014.03 community), and I'm trying to use http caching. I created a twig template for my custom page, and used render (controller...) in that template to render other bits and pieces. I've tried 2 methods to cache the page contents

 

Method #1 : ESI

I first tried to cache all blocks displayed with the render(controller...) function, by replacing them with render_esi and activating esi/fragments in configuration files.

I realised that this was not working, and I started debugging through

 It ssems to me that the problem is that the esi headers of the subrequests (Surrogate-Capability) are removed when the subrequest is forwarded in method onKernelRequestForward, in this file

vendor/ezsystems/ezpublish-kernel/eZ/Bundle/EzPublishCoreBundle/EventListener/RequestEventListener.php

Without these headers,the subrequests are not rendered using esi, and not cached.

Did I miss anything?

Method # 2 : View Caching

I then followed this doc to try activating view caching for my main page

https://doc.ez.no/display/EZP/HttpCache

 

Once again, no luck. I debugged step by step, and I got to the buildResponse method in this file

vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/MVC/Symfony/Controller/Content/ViewController.php

There, $response->setSharedMaxAge is called only if the request's headers contain 'X-User-Hash', which is not there... Going up the call stacked, I noticed that this header was also removed in the same method listed in method #1...

What am I doing wrong?

 

My next try will be implementing a custom viewController to display my page and have total control over the cache, but I'd like to understand what the problem is with what I tried above

 

Thanks!

 

Wednesday 06 August 2014 11:35:31 am

About method 2 (I'd start with that generally, and only move to real ESI with an external proxy after the first is working):

a) are you sure that you set your subcontroller response to public?

b) I looked at the eZ viewcontroller code for both ezp 5.3 and from current master, and I can not confirm what you say:

             if ( $this->getParameter( 'content.ttl_cache' ) === true )
            {
                $response->setSharedMaxAge(
                    $this->getParameter( 'content.default_ttl' )
                );
            }

so it seems that cache is not enabled ONLY when x-user-hash is set

Wednesday 06 August 2014 12:10:15 pm

Thanks for your reply Gaetano.

Actually, the issue I had with X-User-Hash has been fixed in the last community release: https://jira.ez.no/browse/EZP-22667

 

(But I'm still using 2014.03)

 

I've ended up creating a custom view location controller to set cache headers myself. I probably won't need ESI's now, but I think there is definitely a problem there.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from