]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CacheLog/CacheLogPlugin.php
Merge branch '0.9.x'
[quix0rs-gnu-social.git] / plugins / CacheLog / 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 class CacheLogPlugin extends Plugin
54 {
55     function onStartCacheGet(&$key, &$value)
56     {
57         $this->log(LOG_INFO, "Fetching key '$key'");
58         return true;
59     }
60
61     function onEndCacheGet($key, &$value)
62     {
63         if ($value === false) {
64             $this->log(LOG_INFO, "Cache MISS for key '$key'");
65         } else {
66             $this->log(LOG_INFO, "Cache HIT for key '$key'");
67         }
68         return true;
69     }
70
71     function onStartCacheSet(&$key, &$value, &$flag, &$expiry, &$success)
72     {
73         if (empty($value)) {
74             if (is_array($value)) {
75                 $this->log(LOG_INFO, "Setting empty array for key '$key'");
76             } else if (is_null($value)) {
77                 $this->log(LOG_INFO, "Setting null value for key '$key'");
78             } else if (is_string($value)) {
79                 $this->log(LOG_INFO, "Setting empty string for key '$key'");
80             } else if (is_integer($value)) {
81                 $this->log(LOG_INFO, "Setting integer 0 for key '$key'");
82             } else {
83                 $this->log(LOG_INFO, "Setting empty value '$value' for key '$key'");
84             }
85         } else {
86             $this->log(LOG_INFO, "Setting non-empty value for key '$key'");
87         }
88         return true;
89     }
90
91     function onEndCacheSet($key, $value, $flag, $expiry)
92     {
93         $this->log(LOG_INFO, "Done setting cache value for key '$key'");
94         return true;
95     }
96
97     function onStartCacheDelete(&$key, &$success)
98     {
99         $this->log(LOG_INFO, "Deleting cache value for key '$key'");
100         return true;
101     }
102
103     function onEndCacheDelete($key)
104     {
105         $this->log(LOG_INFO, "Done deleting cache value for key '$key'");
106         return true;
107     }
108
109     function onPluginVersion(&$versions)
110     {
111         $versions[] = array('name' => 'CacheLog',
112                             'version' => STATUSNET_VERSION,
113                             'author' => 'Evan Prodromou',
114                             'homepage' => 'http://status.net/wiki/Plugin:CacheLog',
115                             'description' =>
116                             _m('Log reads and writes to the cache.'));
117         return true;
118     }
119 }