3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2009, StatusNet, Inc.
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
40 * Note that since most caching plugins return false for StartCache*
41 * methods, you should add this plugin before them, i.e.
43 * addPlugin('CacheLog');
44 * addPlugin('XCache');
48 * @author Evan Prodromou <evan@status.net>
49 * @copyright 2009 StatusNet, Inc.
50 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
51 * @link http://status.net/
53 class CacheLogPlugin extends Plugin
55 function onStartCacheGet(&$key, &$value)
57 $this->log(LOG_INFO, "Fetching key '$key'");
61 function onEndCacheGet($key, &$value)
63 if ($value === false) {
64 $this->log(LOG_INFO, sprintf('Cache MISS for key "%s"', $key));
66 $this->log(LOG_INFO, sprintf('Cache HIT for key "%s": %s', $key, self::showValue($value)));
71 function onStartCacheSet(&$key, &$value, &$flag, &$expiry, &$success)
73 $this->log(LOG_INFO, "Begin setting cache value for key '$key'");
77 function onEndCacheSet($key, $value, $flag, $expiry)
79 $this->log(LOG_INFO, sprintf('Set cache value %s for key "%s" (flags: %d, expiry %d)',
80 self::showValue($value),
87 function onStartCacheDelete(&$key, &$success)
89 $this->log(LOG_INFO, "Deleting cache value for key '$key'");
93 function onEndCacheDelete($key)
95 $this->log(LOG_INFO, "Done deleting cache value for key '$key'");
99 function onPluginVersion(array &$versions)
101 $versions[] = array('name' => 'CacheLog',
102 'version' => GNUSOCIAL_VERSION,
103 'author' => 'Evan Prodromou',
104 'homepage' => 'http://status.net/wiki/Plugin:CacheLog',
106 // TRANS: Plugin description.
107 _m('Log reads and writes to the cache.'));
111 static function showValue($value)
113 if (is_object($value)) {
114 return sprintf('object of class %s', get_class($value));
115 } else if (is_array($value)) {
116 return sprintf('array of length %d', count($value));
117 } else if (is_string($value)) {
118 return sprintf('string "%s"', $value);
119 } else if (is_integer($value)) {
120 return sprintf('integer %d', $value);
121 } else if (is_null($value)) {