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
|
|
|
|
{
|
2019-06-03 09:56:52 +09:00
|
|
|
const PLUGIN_VERSION = '2.0.0';
|
|
|
|
|
2010-01-04 06:28:00 +09:00
|
|
|
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
|
|
|
|
2019-08-12 23:03:30 +09:00
|
|
|
public function onPluginVersion(array &$versions): bool
|
2010-01-08 10:39:15 +09:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'CacheLog',
|
2019-06-03 09:56:52 +09:00
|
|
|
'version' => self::PLUGIN_VERSION,
|
2010-01-08 10:39:15 +09:00
|
|
|
'author' => 'Evan Prodromou',
|
2019-11-21 09:21:22 +09:00
|
|
|
'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/CacheLog',
|
2010-01-08 10:39:15 +09:00
|
|
|
'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
|
|
|
}
|