In my Symfony2.2 application I am using an onKernelTerminate EventListener so that I can do a piece of "heavy" processing after my response has been rendered so the user receives a faster response time.
In my controller I set an attribute on the request so that when the event listener runs, that attribute can be used to decide if there is something and what to process.
This works perfectly on my dev environment and on a test environment where AppCache is not enabled. But as soon as I enable AppCache (in my app.php) - which I want to do because I use it for all my HTTP caching - the event listener stops working because it seems the Request that I access via the Event in onKernelTerminate has an empty attributes parameter bag.
The attribute I set in the controller isn't available from the request in the PostResponseEvent.
Why does AppCache have this effect? And is there an alternative way to pass data between my controller and an Event Listener which would work with AppCache?
Here's a snippet of code so you can see:
#in my controller
$request->attributes->set('listener-to-process', 'test');
#in my EventListener:
public function onKernelTerminate(PostResponseEvent $event) {
$request = $event->getRequest();
//use this request attribute to decide what to process
if (!$request->attributes->has('listener-to-process')) {
return;
};
$type = $request->attributes->get('listener-to-process');
$status = $this->api->persistTag(type);
return;
}