2010-01-03 21:28:00 +00: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
|
|
|
|
{
|
2019-06-03 01:56:52 +01:00
|
|
|
const PLUGIN_VERSION = '2.0.0';
|
|
|
|
|
2010-01-03 21:28:00 +00:00
|
|
|
function onStartCacheGet(&$key, &$value)
|
|
|
|
{
|
|
|
|
$this->log(LOG_INFO, "Fetching key '$key'");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEndCacheGet($key, &$value)
|
|
|
|
{
|
2010-01-04 19:57:48 +00:00
|
|
|
if ($value === false) {
|
2010-10-22 14:24:19 +01:00
|
|
|
$this->log(LOG_INFO, sprintf('Cache MISS for key "%s"', $key));
|
2010-01-03 21:28:00 +00:00
|
|
|
} else {
|
2010-10-22 14:24:19 +01:00
|
|
|
$this->log(LOG_INFO, sprintf('Cache HIT for key "%s": %s', $key, self::showValue($value)));
|
2010-01-03 21:28:00 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStartCacheSet(&$key, &$value, &$flag, &$expiry, &$success)
|
|
|
|
{
|
2010-10-22 14:24:19 +01:00
|
|
|
$this->log(LOG_INFO, "Begin setting cache value for key '$key'");
|
2010-01-03 21:28:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEndCacheSet($key, $value, $flag, $expiry)
|
|
|
|
{
|
2010-10-22 14:24:19 +01: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-03 21:28:00 +00: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 01:39:15 +00:00
|
|
|
|
2015-06-06 21:04:01 +01:00
|
|
|
function onPluginVersion(array &$versions)
|
2010-01-08 01:39:15 +00:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'CacheLog',
|
2019-06-03 01:56:52 +01:00
|
|
|
'version' => self::PLUGIN_VERSION,
|
2010-01-08 01:39:15 +00:00
|
|
|
'author' => 'Evan Prodromou',
|
2016-01-22 16:38:42 +00:00
|
|
|
'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/CacheLog',
|
2010-01-08 01:39:15 +00:00
|
|
|
'description' =>
|
2011-04-06 17:46:55 +01:00
|
|
|
// TRANS: Plugin description.
|
2010-09-18 23:17:24 +01:00
|
|
|
_m('Log reads and writes to the cache.'));
|
2010-01-08 01:39:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-10-22 14:24:19 +01: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-03 21:28:00 +00:00
|
|
|
}
|