-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from mpchadwick/release/v0.3.0
Release v0.3.0 -> Master
- Loading branch information
Showing
9 changed files
with
109 additions
and
8 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
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
14 changes: 14 additions & 0 deletions
14
app/code/community/Mpchadwick/PageCacheHitRate/Model/SystemLog.php
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,14 @@ | ||
<?php | ||
|
||
class Mpchadwick_PageCacheHitRate_Model_SystemLog | ||
{ | ||
public function log($message, $level) | ||
{ | ||
Mage::log($message, $level, $this->logFile(), true); | ||
} | ||
|
||
protected function logFile() | ||
{ | ||
return 'mpchadwick_pagecachehitrate_system_' . date('Y_m_d') . '.log'; | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
app/code/community/Mpchadwick/PageCacheHitRate/Model/Tracker/Redis.php
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,72 @@ | ||
<?php | ||
|
||
class Mpchadwick_PageCacheHitRate_Model_Tracker_Redis | ||
extends Mpchadwick_PageCacheHitRate_Model_Tracker_Abstract | ||
implements Mpchadwick_PageCacheHitRate_Model_TrackerInterface | ||
{ | ||
const KEY_PREFIX = 'mpchadwick_pagecachehitrate_'; | ||
|
||
/** @var Credis_Client */ | ||
protected $redis; | ||
|
||
/** @var Mpchadwick_PageCacheHitRate_Model_Config */ | ||
protected $config; | ||
|
||
public function __construct() | ||
{ | ||
$this->config = new Mpchadwick_PageCacheHitRate_Model_Config; | ||
$this->logger = new Mpchadwick_PageCacheHitRate_Model_SystemLog; | ||
} | ||
|
||
protected function _track($type, array $args, $alias) | ||
{ | ||
$result = $this->setupConnection($alias); | ||
if (!$result) { | ||
// Bail. setUpConnection handled the error already | ||
return; | ||
} | ||
|
||
$this->redis->hIncrBy( | ||
self::KEY_PREFIX . $type, | ||
$this->field($args), | ||
1 | ||
); | ||
} | ||
|
||
protected function setupConnection($alias) | ||
{ | ||
if (!is_null($this->redis)) { | ||
return; | ||
} | ||
|
||
$prefix = 'trackers/' . $alias . '/'; | ||
$server = $this->config->get($prefix . 'server'); | ||
$port = $this->config->get($prefix . 'port'); | ||
$db = $this->config->get($prefix) . 'database'; | ||
|
||
if (!$server || !$port || !$db) { | ||
$this->logger->log('Missing parameters for creating Redis connection', Zend_Log::ERR); | ||
return false; | ||
} | ||
|
||
try { | ||
$this->redis = new Credis_Client( | ||
$this->config->get($prefix . 'server'), | ||
$this->config->get($prefix . 'port') | ||
); | ||
$this->redis->connect(); | ||
$this->redis->select($this->config->get($prefix . 'database')); | ||
} catch (Exception $e) { | ||
$this->logger->log('Could not establish Redis connection', Zend_Log::ERR); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
protected function field($args) | ||
{ | ||
ksort($args); | ||
return http_build_query($args); | ||
} | ||
} |
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