-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
showing litemage cache statistics on cache management screen
- Loading branch information
1 parent
ee1f0de
commit da6efee
Showing
6 changed files
with
276 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?php | ||
/** | ||
* LiteMage | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* 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 https://opensource.org/licenses/GPL-3.0 . | ||
* | ||
* @package LiteSpeed_LiteMage | ||
* @copyright Copyright (c) 2017 LiteSpeed Technologies, Inc. (https://www.litespeedtech.com) | ||
* @license https://opensource.org/licenses/GPL-3.0 | ||
*/ | ||
|
||
namespace Litespeed\Litemage\Block\Backend\Cache; | ||
|
||
class Management extends \Magento\Backend\Block\Template | ||
{ | ||
/** | ||
* @var \Litespeed\Litemage\Model\Config | ||
*/ | ||
protected $config; | ||
|
||
protected $url; | ||
|
||
|
||
/** | ||
* @var \Magento\Framework\HTTP\ZendClientFactory | ||
*/ | ||
protected $httpClientFactory; | ||
/** | ||
* @param \Magento\Backend\Block\Template\Context $context | ||
* @param \Litespeed\Litemage\Model\Config $config, | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\Block\Template\Context $context, | ||
\Litespeed\Litemage\Model\Config $config, | ||
\Magento\Framework\HTTP\ZendClientFactory $httpClientFactory, | ||
\Magento\Framework\Url $url, | ||
array $data = []) | ||
{ | ||
parent::__construct($context, $data); | ||
$this->config = $config; | ||
$this->httpClientFactory = $httpClientFactory; | ||
$this->url = $url; | ||
} | ||
|
||
/** | ||
* Get clean cache url | ||
* | ||
* @return string | ||
*/ | ||
public function getPurgeUrl($type) | ||
{ | ||
if ($type == 'Refresh') { | ||
return $this->getUrl('*/*/cache/index'); | ||
} | ||
else { | ||
$types = array('All', 'Tag', 'Url'); | ||
|
||
if (in_array($type, $types)) { | ||
return $this->getUrl('*/litemageCache/purge' . $type); | ||
} | ||
else { | ||
return $this->getUrl('*/litemageCache/purgeAll'); | ||
} | ||
} | ||
} | ||
|
||
public function getCacheStatistics() | ||
{ | ||
$statUri = '/__LSCACHE/STATS'; | ||
$base = $this->url->getBaseUrl(); | ||
if ((stripos($base, 'http') !== false) && ($pos = strpos($base, '://'))) { | ||
$pos2 = strpos($base, '/', $pos+ 4); | ||
if ($pos === false) { | ||
$statBase = $base; | ||
} | ||
else { | ||
$statBase = substr($base, 0, $pos2); | ||
if (substr($base, $pos2+1, 1) == '~') { | ||
if ($pos3 = strpos($base, '/', $pos2+1)) { | ||
$statBase = substr($base, 0, $pos3); | ||
} | ||
} | ||
} | ||
} | ||
$statUri = $statBase . $statUri; | ||
|
||
$client = $this->httpClientFactory->create(); | ||
$client->setUri($statUri); | ||
|
||
try { | ||
$response = $client->request() ; | ||
$data = trim($response->getBody()); | ||
if ($data{0} !== '{') { | ||
return null; | ||
} | ||
|
||
$data1 = json_decode($data, true); | ||
$data2 = array_values($data1); | ||
if (count($data2)) { | ||
$stats = $data2[0]; | ||
switch ($stats['LITEMAGE_PLAN']) { | ||
case 11: $stats['plan'] = 'LiteMage Standard'; | ||
$stats['plan_desc'] = 'up to 25000 publicly cached objects'; | ||
break; | ||
case 3: $stats['plan'] = 'LiteMage Unlimited'; | ||
$stats['plan_desc'] = 'unlimited publicly cached objects'; | ||
break; | ||
case 9: | ||
default: | ||
$stats['plan'] = 'LiteMage Starter'; | ||
$stats['plan_desc'] = 'up to 1500 publicly cached objects'; | ||
} | ||
return $stats; | ||
} | ||
} catch ( Exception $e ) { | ||
} | ||
return null; | ||
} | ||
|
||
|
||
/** | ||
* Check if block can be displayed | ||
* | ||
* @return bool | ||
*/ | ||
public function canShowButton() | ||
{ | ||
return $this->config->moduleEnabled(); | ||
} | ||
|
||
|
||
} |
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
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,33 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* LiteMage | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* 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 https://opensource.org/licenses/GPL-3.0 . | ||
* | ||
* @package LiteSpeed_LiteMage | ||
* @copyright Copyright (c) 2017 LiteSpeed Technologies, Inc. (https://www.litespeedtech.com) | ||
* @license https://opensource.org/licenses/GPL-3.0 | ||
*/ | ||
--> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceContainer name="content"> | ||
<block class="Litespeed\Litemage\Block\Backend\Cache\Management" name="cache.litemage" template="Litespeed_Litemage::system/cache/litemage.phtml"/> | ||
</referenceContainer> | ||
</body> | ||
</page> | ||
|
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 | ||
/** | ||
* LiteMage | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* 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 https://opensource.org/licenses/GPL-3.0 . | ||
* | ||
* @package LiteSpeed_LiteMage | ||
* @copyright Copyright (c) 2017 LiteSpeed Technologies, Inc. (https://www.litespeedtech.com) | ||
* @license https://opensource.org/licenses/GPL-3.0 | ||
*/ | ||
?> | ||
|
||
<?php | ||
if ($block->canShowButton()): | ||
?> | ||
<br> | ||
<div class="additional-cache-management"> | ||
<h2> | ||
<span><?php /* @escapeNotVerified */ echo __('LiteMage Cache Management (LiteSpeed Web Server)') ?></span> | ||
</h2> | ||
</div> | ||
<?php | ||
|
||
|
||
if ($stats = $block->getCacheStatistics()) : | ||
?> | ||
|
||
<div><table class="data-grid"> | ||
<tr> | ||
<th class="data-grid-th" width="25%"><?php echo __('Current LiteMage Plan');?></th> | ||
<th class="data-grid-th" width="25%"><?php echo __('Public Cache Hits'); ?></th> | ||
<th class="data-grid-th" width="25%"><?php echo __('Full Page Hits'); ?></th> | ||
<th class="data-grid-th" width="25%"><?php echo __('LiteMage Cached Objects'); ?></th> | ||
</tr> | ||
<?php | ||
$severity = $stats['LITEMAGE_LIMITED'] > 0 ? 'grid-severity-critical' : 'grid-severity-notice'; | ||
$noteclass = 'notifications-entry-description'; | ||
echo '<tr><td><div class="' . $severity . '">' . $stats['plan'] | ||
. '</div></td><td>' . $stats['PUB_HITS'] | ||
. '<div class="' . $noteclass . '">' . __('Number of requests that hit public cache since last flush all') | ||
. '</div></td><td>' . $stats['FULLPAGE_HITS'] | ||
. '<div class="' . $noteclass . '">' . __('Number of requests fully served from cache (no PHP invoked) since last flush all') | ||
. '</div></td><td>' . $stats['LITEMAGE_OBJS'] | ||
. '<div class="' . $noteclass . '">' . __('Current publicly cached object count') | ||
. "</div></td></tr>\n"; | ||
?> | ||
<tr> | ||
<th class="data-grid-th"><?php echo __('Available Plan Options');?> | ||
</th> | ||
<th class="data-grid-th"><?php echo __('Private Cache Hits'); ?></th> | ||
<th class="data-grid-th"><?php echo __('Partial Page Hits'); ?></th> | ||
<th class="data-grid-th"><?php echo __('Not Cached (Limited by Plan)'); ?></th> | ||
</tr> | ||
<?php | ||
echo '<tr><td>' . __('LiteMage Starter') | ||
. '<div class="' . $noteclass . '">' . __('1,500 publicly cached objects') | ||
. '</div>' . __('LiteMage Standard') | ||
. '<div class="' . $noteclass . '">' . __('25,000 publicly cached objects') | ||
. '</div>' . __('LiteMage Unlimited') | ||
. '<div class="' . $noteclass . '">' . __('unlimited publicly cached objects') | ||
. '</div></td><td>'. $stats['PVT_HITS'] | ||
. '<div class="' . $noteclass . '">' . __('Number of requests that hit private cache since last flush all') | ||
. '</div></td><td>'. $stats['PARTIAL_HITS'] | ||
. '<div class="' . $noteclass . '">' . __('Number of requests partially served from cache (some data retrieved from Magento) since last flush all') | ||
. '</div></td><td><div class="' . $severity . '">' . $stats['LITEMAGE_LIMITED'] | ||
. '</div><div class="' . $noteclass . '">' . __('Number of requests not served from cache due to plan limitation. You can upgrade your LiteMage plan if this value is not zero.') | ||
. "</div></td></tr>\n"; | ||
?> | ||
</table> | ||
</div> | ||
<?php | ||
endif; | ||
?> | ||
|
||
<?php | ||
|
||
endif; | ||
|
||
?> | ||
|