]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CacheLogPlugin.php
Merge branch 'master' of gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / plugins / CacheLogPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2009, StatusNet, Inc.
5  *
6  * Logs cache access
7  *
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Cache
24  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Log cache access
39  *
40  * Note that since most caching plugins return false for StartCache*
41  * methods, you should add this plugin before them, i.e.
42  *
43  *     addPlugin('CacheLog');
44  *     addPlugin('XCache');
45  *
46  * @category  Cache
47  * @package   StatusNet
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/
52  */
53
54 class CacheLogPlugin extends Plugin
55 {
56     function onStartCacheGet(&$key, &$value)
57     {
58         $this->log(LOG_INFO, "Fetching key '$key'");
59         return true;
60     }
61
62     function onEndCacheGet($key, &$value)
63     {
64         if ($value === false) {
65             $this->log(LOG_INFO, "Cache MISS for key '$key'");
66         } else {
67             $this->log(LOG_INFO, "Cache HIT for key '$key'");
68         }
69         return true;
70     }
71
72     function onStartCacheSet(&$key, &$value, &$flag, &$expiry, &$success)
73     {
74         if (empty($value)) {
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'");
83             } else {
84                 $this->log(LOG_INFO, "Setting empty value '$value' for key '$key'");
85             }
86         } else {
87             $this->log(LOG_INFO, "Setting non-empty value for key '$key'");
88         }
89         return true;
90     }
91
92     function onEndCacheSet($key, $value, $flag, $expiry)
93     {
94         $this->log(LOG_INFO, "Done setting cache value for key '$key'");
95         return true;
96     }
97
98     function onStartCacheDelete(&$key, &$success)
99     {
100         $this->log(LOG_INFO, "Deleting cache value for key '$key'");
101         return true;
102     }
103
104     function onEndCacheDelete($key)
105     {
106         $this->log(LOG_INFO, "Done deleting cache value for key '$key'");
107         return true;
108     }
109
110     function onPluginVersion(&$versions)
111     {
112         $versions[] = array('name' => 'CacheLog',
113                             'version' => STATUSNET_VERSION,
114                             'author' => 'Evan Prodromou',
115                             'homepage' => 'http://status.net/wiki/Plugin:CacheLog',
116                             'description' =>
117                             _m('Log reads and writes to the cache'));
118         return true;
119     }
120 }
121