2010-01-04 06:28:00 +09:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2009, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* Logs cache access
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @category Cache
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2009 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
// This check helps protect against security problems;
|
|
|
|
// your code file can't be executed directly from the web.
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log cache access
|
|
|
|
*
|
|
|
|
* Note that since most caching plugins return false for StartCache*
|
|
|
|
* methods, you should add this plugin before them, i.e.
|
|
|
|
*
|
|
|
|
* addPlugin('CacheLog');
|
|
|
|
* addPlugin('XCache');
|
|
|
|
*
|
|
|
|
* @category Cache
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2009 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
class CacheLogPlugin extends Plugin
|
|
|
|
{
|
|
|
|
function onStartCacheGet(&$key, &$value)
|
|
|
|
{
|
|
|
|
$this->log(LOG_INFO, "Fetching key '$key'");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEndCacheGet($key, &$value)
|
|
|
|
{
|
2010-01-05 04:57:48 +09:00
|
|
|
if ($value === false) {
|
2010-10-22 22:24:19 +09:00
|
|
|
$this->log(LOG_INFO, sprintf('Cache MISS for key "%s"', $key));
|
2010-01-04 06:28:00 +09:00
|
|
|
} else {
|
2010-10-22 22:24:19 +09:00
|
|
|
$this->log(LOG_INFO, sprintf('Cache HIT for key "%s": %s', $key, self::showValue($value)));
|
2010-01-04 06:28:00 +09:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStartCacheSet(&$key, &$value, &$flag, &$expiry, &$success)
|
|
|
|
{
|
2010-10-22 22:24:19 +09:00
|
|
|
$this->log(LOG_INFO, "Begin setting cache value for key '$key'");
|
2010-01-04 06:28:00 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEndCacheSet($key, $value, $flag, $expiry)
|
|
|
|
{
|
2010-10-22 22:24:19 +09:00
|
|
|
$this->log(LOG_INFO, sprintf('Set cache value %s for key "%s" (flags: %d, expiry %d)',
|
|
|
|
self::showValue($value),
|
|
|
|
$key,
|
|
|
|
$flag,
|
|
|
|
$expiry));
|
2010-01-04 06:28:00 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStartCacheDelete(&$key, &$success)
|
|
|
|
{
|
|
|
|
$this->log(LOG_INFO, "Deleting cache value for key '$key'");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEndCacheDelete($key)
|
|
|
|
{
|
|
|
|
$this->log(LOG_INFO, "Done deleting cache value for key '$key'");
|
|
|
|
return true;
|
|
|
|
}
|
2010-01-08 10:39:15 +09:00
|
|
|
|
2015-06-07 05:04:01 +09:00
|
|
|
function onPluginVersion(array &$versions)
|
2010-01-08 10:39:15 +09:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'CacheLog',
|
2013-11-01 21:51:41 +09:00
|
|
|
'version' => GNUSOCIAL_VERSION,
|
2010-01-08 10:39:15 +09:00
|
|
|
'author' => 'Evan Prodromou',
|
|
|
|
'homepage' => 'http://status.net/wiki/Plugin:CacheLog',
|
|
|
|
'description' =>
|
2011-04-07 01:46:55 +09:00
|
|
|
// TRANS: Plugin description.
|
2010-09-19 07:17:24 +09:00
|
|
|
_m('Log reads and writes to the cache.'));
|
2010-01-08 10:39:15 +09:00
|
|
|
return true;
|
|
|
|
}
|
2010-10-22 22:24:19 +09:00
|
|
|
|
|
|
|
static function showValue($value)
|
|
|
|
{
|
|
|
|
if (is_object($value)) {
|
|
|
|
return sprintf('object of class %s', get_class($value));
|
|
|
|
} else if (is_array($value)) {
|
|
|
|
return sprintf('array of length %d', count($value));
|
|
|
|
} else if (is_string($value)) {
|
|
|
|
return sprintf('string "%s"', $value);
|
|
|
|
} else if (is_integer($value)) {
|
|
|
|
return sprintf('integer %d', $value);
|
|
|
|
} else if (is_null($value)) {
|
|
|
|
return 'null';
|
|
|
|
} else {
|
|
|
|
return 'unknown';
|
|
|
|
}
|
|
|
|
}
|
2010-01-04 06:28:00 +09:00
|
|
|
}
|