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/
54 class CacheLogPlugin extends Plugin
56 function onStartCacheGet(&$key, &$value)
58 $this->log(LOG_INFO, "Fetching key '$key'");
62 function onEndCacheGet($key, &$value)
64 if ($value === false) {
65 $this->log(LOG_INFO, "Cache MISS for key '$key'");
67 $this->log(LOG_INFO, "Cache HIT for key '$key'");
72 function onStartCacheSet(&$key, &$value, &$flag, &$expiry, &$success)
75 if (is_array($value)) {
76 $this->log(LOG_INFO, "Setting empty array for key '$key'");
77 } else if (is_null($value)) {
78 $this->log(LOG_INFO, "Setting null value for key '$key'");
79 } else if (is_string($value)) {
80 $this->log(LOG_INFO, "Setting empty string for key '$key'");
81 } else if (is_integer($value)) {
82 $this->log(LOG_INFO, "Setting integer 0 for key '$key'");
84 $this->log(LOG_INFO, "Setting empty value '$value' for key '$key'");
87 $this->log(LOG_INFO, "Setting non-empty value for key '$key'");
92 function onEndCacheSet($key, $value, $flag, $expiry)
94 $this->log(LOG_INFO, "Done setting cache value for key '$key'");
98 function onStartCacheDelete(&$key, &$success)
100 $this->log(LOG_INFO, "Deleting cache value for key '$key'");
104 function onEndCacheDelete($key)
106 $this->log(LOG_INFO, "Done deleting cache value for key '$key'");
110 function onPluginVersion(&$versions)
112 $versions[] = array('name' => 'CacheLog',
113 'version' => STATUSNET_VERSION,
114 'author' => 'Evan Prodromou',
115 'homepage' => 'http://status.net/wiki/Plugin:CacheLog',
117 _m('Log reads and writes to the cache'));