This repository has been archived by the owner on Jul 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
685 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,36 @@ | ||
Mage-Cache-Viewer | ||
================= | ||
# Meanbee_CacheViewer | ||
|
||
View the status of Magento Caches | ||
Meanbee_CacheViewer provides interfaces for inspecting Magento cache. | ||
|
||
Access from System > Cache Management > View Cache Statistics. | ||
## Usage | ||
|
||
### Analysing Block Cache | ||
|
||
Enabled with a configuration setting in `System` » `Configuration` » `Cache Viewer`, the frontend overlay indicates | ||
which blocks were generated (red) and which were retrieved from the block_html cache (green) as well as showing the | ||
last modified time for each block and the total time taken to dispatch the request. | ||
|
||
This will become enabled for the frontend and the admin area and is controlled by the control bar added at the bottom of the viewport. | ||
|
||
 | ||
|
||
 | ||
|
||
### View Cache Contents | ||
|
||
The backend interface, found in `System` » `Cache Management` » `View Cache Contents` in the Administration area, allows | ||
viewing, inspecting or deleting all of the cache entries present in the Magento cache. | ||
|
||
 | ||
|
||
## License | ||
|
||
Meanbee_CacheViewer, a Magento extension for inspecting cache contents. | ||
|
||
Copyright (C) 2013, Meanbee Limited. | ||
|
||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
class Meanbee_CacheViewer_Block_Toolbar extends Mage_Core_Block_Template { | ||
|
||
public function _toHtml() { | ||
|
||
if(!Mage::getStoreConfig(Meanbee_CacheViewer_Helper_Data::XML_PATH_CACHEVIEWER_BLOCKS_VIEW_FRONTEND)) | ||
return; | ||
|
||
return parent::_toHtml(); | ||
} | ||
|
||
/** | ||
* Return the configured default cookie path. | ||
* | ||
* @return mixed | ||
*/ | ||
protected function getCookiePath() { | ||
return Mage::getSingleton('core/cookie')->getPath(); | ||
} | ||
|
||
/** | ||
* Return the configured default cookie domain. | ||
* | ||
* @return string | ||
*/ | ||
protected function getCookieDomain() { | ||
$domain = Mage::getSingleton('core/cookie')->getDomain(); | ||
if (!empty($domain[0]) && ($domain[0] !== '.')) { | ||
$domain = '.'.$domain; | ||
} | ||
return $domain; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
<?php | ||
|
||
class Meanbee_CacheViewer_Helper_Data extends Mage_Core_Helper_Abstract {} | ||
class Meanbee_CacheViewer_Helper_Data extends Mage_Core_Helper_Abstract { | ||
|
||
const XML_PATH_CACHEVIEWER_BLOCKS_VIEW_FRONTEND = "cacheviewer/blocks/view_frontend"; | ||
|
||
public function isShowCacheStatusOnFrontend() { | ||
return Mage::getStoreConfigFlag(self::XML_PATH_CACHEVIEWER_BLOCKS_VIEW_FRONTEND); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
class Meanbee_CacheViewer_Model_Observer extends Mage_Core_Model_Abstract { | ||
|
||
const EVENT_BEFORE = 'core_block_abstract_to_html_before'; | ||
const EVENT_AFTER = 'core_block_abstract_to_html_after'; | ||
|
||
/** @var Meanbee_CacheViewer_Helper_Data */ | ||
protected $_helper; | ||
|
||
protected $_dispatch_start_time; | ||
|
||
public function _construct() { | ||
parent::_construct(); | ||
|
||
$this->_helper = Mage::helper('cacheviewer'); | ||
} | ||
|
||
/** | ||
* Add cache block status | ||
* @param Varien_Event_Observer $observer | ||
* @return void | ||
*/ | ||
public function addBlockCacheStatuses(Varien_Event_Observer $observer) { | ||
$event = $observer->getEvent(); | ||
$block = $event->getBlock(); | ||
$transportObject = $event->getTransport(); | ||
|
||
if (!$this->_helper->isShowCacheStatusOnFrontend()) { | ||
return; | ||
} | ||
|
||
if (in_array(get_class($block), array("Mage_Page_Block_Html", "Mage_Adminhtml_Block_Page"))) { | ||
return; | ||
} | ||
|
||
// Get cache status | ||
$cache = Mage::app()->getCache()->test(strtoupper($block->getCacheKey())); | ||
$lastModified = date(DATE_ATOM, time()); | ||
$blockName = get_class($block); | ||
$cacheClass = ""; | ||
|
||
|
||
// If cached, get last modified date and add cached class for css. | ||
if($cache) { | ||
$lastModified = date(DATE_ATOM, $cache); | ||
$cacheClass = " cacheviewer-block-cached"; | ||
} | ||
|
||
// Get transport object passed through event and wrap out hints around it. | ||
$html = $transportObject->getHtml(); | ||
$html = <<<HTML | ||
<div class="cacheviewer-container clearer"> | ||
<div class="cacheviewer-block{$cacheClass}"> | ||
<div class="cacheviewer-hints"> | ||
<span class="cacheviewer-lastmodified">{$lastModified}</span> | ||
<span class="cacheviewer-name">{$blockName}</span> | ||
</div> | ||
</div> | ||
{$html} | ||
</div> | ||
HTML; | ||
|
||
$transportObject->setHtml($html); | ||
|
||
return; | ||
} | ||
|
||
/** | ||
* Start the timer for tracking dispatch time. | ||
* Observe: controller_action_predispatch | ||
* | ||
* @param Varien_Event_Observer $observer | ||
*/ | ||
public function startTimer(Varien_Event_Observer $observer) { | ||
$this->_dispatch_start_time = microtime(true); | ||
} | ||
|
||
/** | ||
* Stop the timer tracking dispatch time and set the elapsed time in a cookie. | ||
* | ||
* @param Varien_Event_Observer $observer | ||
*/ | ||
public function stopTimer(Varien_Event_Observer $observer) { | ||
$dispatch_finish_time = microtime(true); | ||
|
||
$elapsed_time = $dispatch_finish_time - $this->_dispatch_start_time; | ||
|
||
if ($this->_helper->isShowCacheStatusOnFrontend()) { | ||
Mage::getSingleton('core/cookie')->set("cacheviewer_dispatch_time", sprintf("%.3fs", $elapsed_time), 0, null, null, null, false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.