-
Notifications
You must be signed in to change notification settings - Fork 4
/
Observer.php
65 lines (59 loc) · 1.92 KB
/
Observer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class Mpchadwick_PageCacheHitRate_Model_Observer
{
/**
* Handle the controller_front_send_response_before event.
*
* This won't happen in the case of a hit. However it will happen for both
* a miss and a partial hit.
*
* @param Varien_Event_Observer $observer
* @return void
*/
public function handleControllerFrontSendResponseBefore(Varien_Event_Observer $observer)
{
$factory = Mage::getModel('mpchadwick_pagecachehitrate/trackerFactory');
$tracker = $factory->getTracker();
// A tracker isn't configured. Bail.
if (!$tracker) {
return;
}
$paramProvider = Mage::getModel('mpchadwick_pagecachehitrate/tracker_paramProvider');
$params = $paramProvider->baseParams() + array(
'type' => $this->type(),
'route' => $this->trackerRoute(),
);
// @todo Might be useful to know what containers prevented a full hit in the case of a partial
$tracker->track($params);
}
/**
* Get the type of response.
*
* Enterprise_PageCache_Model_Processor::_processContent() will store an array of
* `cached_page_containers` in Mage::_registry for partial hits.
*
* @return string
*/
protected function type()
{
if (Mage::registry('cached_page_containers')) {
return 'partial';
} else {
return 'miss';
}
}
/**
* Get the route for tracking.
*
* Same mechanics used to store metadata for page cache, which is our only
* option for determining the route when coming from page cache.
*
* @return string
*/
protected function trackerRoute()
{
return Mage::app()->getRequest()->getRequestedRouteName() . '/' .
Mage::app()->getRequest()->getRequestedControllerName() . '/' .
Mage::app()->getRequest()->getRequestedActionName();
}
}