Version Description
Download this release
Release Info
Developer | Hristo Sg |
Plugin | SG Optimizer |
Version | 2.2.9 |
Comparing to | |
See all releases |
Code changes from version 2.2 to 2.2.9
- class-sg-cachepress-memcache.php +30 -9
- class-sg-cachepress.php +13 -0
- memcache.tpl +6 -1
- memcached.tpl +466 -0
- readme.txt +1 -1
- sg-cachepress.php +3 -2
- views/sg-cache.php +1 -1
class-sg-cachepress-memcache.php
CHANGED
@@ -162,12 +162,28 @@ class SG_CachePress_Memcache {
|
|
162 |
return false;
|
163 |
|
164 |
$object_cache_file = $this->get_object_cache_file();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
-
$memcache
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
return $this->create_memcached_dropin( $ip, $port );
|
171 |
|
172 |
$this->remove_memcached_dropin();
|
173 |
|
@@ -183,10 +199,15 @@ class SG_CachePress_Memcache {
|
|
183 |
*
|
184 |
* @return bool True on retrieving exactly the value set, false otherwise.
|
185 |
*/
|
186 |
-
protected function memcached_connection_is_working( $connection ) {
|
187 |
if ( ! $connection )
|
188 |
return false;
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
190 |
if ( @$connection->get( 'SGCP_Memcached_Test' ) === 'Test!1' )
|
191 |
{
|
192 |
$connection->flush();
|
@@ -205,9 +226,9 @@ class SG_CachePress_Memcache {
|
|
205 |
*
|
206 |
* @return bool True if the template was successfully copied, false otherwise.
|
207 |
*/
|
208 |
-
protected function create_memcached_dropin( $ip, $port ) {
|
209 |
$object_cache_file = $this->get_object_cache_file();
|
210 |
-
$template = file_get_contents( dirname( __FILE__ ) .
|
211 |
$find = '@changedefaults@';
|
212 |
$replace = "{$ip}:{$port}";
|
213 |
$new_object_cache = str_replace( $find, $replace, $template );
|
162 |
return false;
|
163 |
|
164 |
$object_cache_file = $this->get_object_cache_file();
|
165 |
+
|
166 |
+
if ( class_exists( 'Memcached' ) )
|
167 |
+
{
|
168 |
+
//Use Memcached
|
169 |
+
$memcache = new Memcached();
|
170 |
+
@$memcache->addServer( $ip, $port );
|
171 |
+
$file = 'memcached.tpl';
|
172 |
+
$type = 'Memcached';
|
173 |
+
}
|
174 |
+
else
|
175 |
+
{
|
176 |
+
//Use Memcache
|
177 |
+
$memcache = new Memcache;
|
178 |
+
@$memcache->connect( $ip, $port );
|
179 |
+
$file = 'memcache.tpl';
|
180 |
+
$type = 'Memcache';
|
181 |
+
}
|
182 |
|
183 |
+
if ( $this->memcached_connection_is_working( $memcache, $type ) )
|
184 |
+
{
|
185 |
+
return $this->create_memcached_dropin( $ip, $port, $file );
|
186 |
+
}
|
|
|
187 |
|
188 |
$this->remove_memcached_dropin();
|
189 |
|
199 |
*
|
200 |
* @return bool True on retrieving exactly the value set, false otherwise.
|
201 |
*/
|
202 |
+
protected function memcached_connection_is_working( $connection, $type = 'Memcache' ) {
|
203 |
if ( ! $connection )
|
204 |
return false;
|
205 |
+
|
206 |
+
if( $type == 'Memcache' )
|
207 |
+
@$connection->set( 'SGCP_Memcached_Test', 'Test!1', MEMCACHE_COMPRESSED, 50 );
|
208 |
+
elseif( $type == 'Memcached' )
|
209 |
+
@$connection->set( 'SGCP_Memcached_Test', 'Test!1', 50 );
|
210 |
+
|
211 |
if ( @$connection->get( 'SGCP_Memcached_Test' ) === 'Test!1' )
|
212 |
{
|
213 |
$connection->flush();
|
226 |
*
|
227 |
* @return bool True if the template was successfully copied, false otherwise.
|
228 |
*/
|
229 |
+
protected function create_memcached_dropin( $ip, $port, $file ) {
|
230 |
$object_cache_file = $this->get_object_cache_file();
|
231 |
+
$template = file_get_contents( dirname( __FILE__ ) . "/" . $file );
|
232 |
$find = '@changedefaults@';
|
233 |
$replace = "{$ip}:{$port}";
|
234 |
$new_object_cache = str_replace( $find, $replace, $template );
|
class-sg-cachepress.php
CHANGED
@@ -90,6 +90,7 @@ class SG_CachePress {
|
|
90 |
* disabled or plugin is activated on an individual blog.
|
91 |
*/
|
92 |
public static function activate( $network_wide ) {
|
|
|
93 |
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
|
94 |
if ( $network_wide ) {
|
95 |
// Get all blog ids
|
@@ -107,6 +108,18 @@ class SG_CachePress {
|
|
107 |
self::single_activate();
|
108 |
}
|
109 |
self::disable_first_run_option();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
}
|
111 |
|
112 |
/**
|
90 |
* disabled or plugin is activated on an individual blog.
|
91 |
*/
|
92 |
public static function activate( $network_wide ) {
|
93 |
+
|
94 |
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
|
95 |
if ( $network_wide ) {
|
96 |
// Get all blog ids
|
108 |
self::single_activate();
|
109 |
}
|
110 |
self::disable_first_run_option();
|
111 |
+
self::clean_object_cache();
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Cleans object cache to replace it with newer one
|
116 |
+
*/
|
117 |
+
private static function clean_object_cache()
|
118 |
+
{
|
119 |
+
$file = trailingslashit( WP_CONTENT_DIR ) . 'object-cache.php';
|
120 |
+
if ( is_readable( $file ) ) {
|
121 |
+
unlink( $file );
|
122 |
+
}
|
123 |
}
|
124 |
|
125 |
/**
|
memcache.tpl
CHANGED
@@ -12,6 +12,10 @@ Install this file to wp-content/object-cache.php
|
|
12 |
|
13 |
// Users with setups where multiple installs share a common wp-config.php or $table_prefix
|
14 |
// can use this to guarantee uniqueness for the keys generated by this object cache
|
|
|
|
|
|
|
|
|
15 |
if ( !defined( 'WP_CACHE_KEY_SALT' ) )
|
16 |
define( 'WP_CACHE_KEY_SALT', substr(md5(dirname(__FILE__)),7));
|
17 |
|
@@ -404,4 +408,5 @@ class WP_Object_Cache {
|
|
404 |
$this->cache_misses =& $this->stats['add'];
|
405 |
}
|
406 |
}
|
407 |
-
|
|
12 |
|
13 |
// Users with setups where multiple installs share a common wp-config.php or $table_prefix
|
14 |
// can use this to guarantee uniqueness for the keys generated by this object cache
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Memcached Redux
|
4 |
+
Description: The real Memcached (not Memcache) backend for the WP Object Cache.
|
5 |
+
Version: 0.1.3
|
6 |
+
Plugin URI: http://wordpress.org/extend/plugins/memcached/
|
7 |
+
Author: Scott Taylor - uses code from Ryan Boren, Denis de Bernardy, Matt Martz, Mike Schroder
|
8 |
+
|
9 |
+
Install this file to wp-content/object-cache.php
|
10 |
+
*/
|
11 |
+
|
12 |
+
if ( class_exists( 'Memcached' ) )
|
13 |
+
{
|
14 |
+
|
15 |
+
if ( !defined( 'WP_CACHE_KEY_SALT' ) ) {
|
16 |
+
define( 'WP_CACHE_KEY_SALT', '' );
|
17 |
+
}
|
18 |
+
|
19 |
+
function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {
|
20 |
+
global $wp_object_cache;
|
21 |
+
|
22 |
+
return $wp_object_cache->add( $key, $data, $group, $expire );
|
23 |
+
}
|
24 |
+
|
25 |
+
function wp_cache_incr( $key, $n = 1, $group = '' ) {
|
26 |
+
global $wp_object_cache;
|
27 |
+
|
28 |
+
return $wp_object_cache->incr( $key, $n, $group );
|
29 |
+
}
|
30 |
+
|
31 |
+
function wp_cache_decr( $key, $n = 1, $group = '' ) {
|
32 |
+
global $wp_object_cache;
|
33 |
+
|
34 |
+
return $wp_object_cache->decr( $key, $n, $group );
|
35 |
+
}
|
36 |
+
|
37 |
+
function wp_cache_close() {
|
38 |
+
global $wp_object_cache;
|
39 |
+
|
40 |
+
return $wp_object_cache->close();
|
41 |
+
}
|
42 |
+
|
43 |
+
function wp_cache_delete( $key, $group = '' ) {
|
44 |
+
global $wp_object_cache;
|
45 |
+
|
46 |
+
return $wp_object_cache->delete( $key, $group );
|
47 |
+
}
|
48 |
+
|
49 |
+
function wp_cache_flush() {
|
50 |
+
global $wp_object_cache;
|
51 |
+
|
52 |
+
return $wp_object_cache->flush();
|
53 |
+
}
|
54 |
+
|
55 |
+
function wp_cache_get( $key, $group = '' ) {
|
56 |
+
global $wp_object_cache;
|
57 |
+
|
58 |
+
return $wp_object_cache->get( $key, $group );
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* $keys_and_groups = array(
|
63 |
+
* array( 'key', 'group' ),
|
64 |
+
* array( 'key', '' ),
|
65 |
+
* array( 'key', 'group' ),
|
66 |
+
* array( 'key' )
|
67 |
+
* );
|
68 |
+
*
|
69 |
+
*/
|
70 |
+
function wp_cache_get_multi( $key_and_groups, $bucket = 'default' ) {
|
71 |
+
global $wp_object_cache;
|
72 |
+
|
73 |
+
return $wp_object_cache->get_multi( $key_and_groups, $bucket );
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* $items = array(
|
78 |
+
* array( 'key', 'data', 'group' ),
|
79 |
+
* array( 'key', 'data' )
|
80 |
+
* );
|
81 |
+
*
|
82 |
+
*/
|
83 |
+
function wp_cache_set_multi( $items, $expire = 0, $group = 'default' ) {
|
84 |
+
global $wp_object_cache;
|
85 |
+
|
86 |
+
return $wp_object_cache->set_multi( $items, $expire = 0, $group = 'default' );
|
87 |
+
}
|
88 |
+
|
89 |
+
function wp_cache_init() {
|
90 |
+
global $wp_object_cache;
|
91 |
+
|
92 |
+
$wp_object_cache = new WP_Object_Cache();
|
93 |
+
}
|
94 |
+
|
95 |
+
function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) {
|
96 |
+
global $wp_object_cache;
|
97 |
+
|
98 |
+
return $wp_object_cache->replace( $key, $data, $group, $expire );
|
99 |
+
}
|
100 |
+
|
101 |
+
function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
|
102 |
+
global $wp_object_cache;
|
103 |
+
|
104 |
+
if ( defined( 'WP_INSTALLING' ) == false )
|
105 |
+
return $wp_object_cache->set( $key, $data, $group, $expire );
|
106 |
+
else
|
107 |
+
return $wp_object_cache->delete( $key, $group );
|
108 |
+
}
|
109 |
+
|
110 |
+
function wp_cache_add_global_groups( $groups ) {
|
111 |
+
global $wp_object_cache;
|
112 |
+
|
113 |
+
$wp_object_cache->add_global_groups( $groups );
|
114 |
+
}
|
115 |
+
|
116 |
+
function wp_cache_add_non_persistent_groups( $groups ) {
|
117 |
+
global $wp_object_cache;
|
118 |
+
|
119 |
+
$wp_object_cache->add_non_persistent_groups( $groups );
|
120 |
+
}
|
121 |
+
|
122 |
+
class WP_Object_Cache {
|
123 |
+
var $global_groups = array();
|
124 |
+
|
125 |
+
var $no_mc_groups = array();
|
126 |
+
|
127 |
+
var $cache = array();
|
128 |
+
var $mc = array();
|
129 |
+
var $stats = array();
|
130 |
+
var $group_ops = array();
|
131 |
+
|
132 |
+
var $cache_enabled = true;
|
133 |
+
var $default_expiration = 0;
|
134 |
+
|
135 |
+
function add( $id, $data, $group = 'default', $expire = 0 ) {
|
136 |
+
$key = $this->key( $id, $group );
|
137 |
+
|
138 |
+
if ( is_object( $data ) )
|
139 |
+
$data = clone $data;
|
140 |
+
|
141 |
+
if ( in_array( $group, $this->no_mc_groups ) ) {
|
142 |
+
$this->cache[$key] = $data;
|
143 |
+
return true;
|
144 |
+
} elseif ( isset( $this->cache[$key] ) && $this->cache[$key] !== false ) {
|
145 |
+
return false;
|
146 |
+
}
|
147 |
+
|
148 |
+
$mc =& $this->get_mc( $group );
|
149 |
+
$expire = ( $expire == 0) ? $this->default_expiration : $expire;
|
150 |
+
$result = $mc->add( $key, $data, $expire );
|
151 |
+
|
152 |
+
if ( false !== $result ) {
|
153 |
+
@ ++$this->stats['add'];
|
154 |
+
$this->group_ops[$group][] = "add $id";
|
155 |
+
$this->cache[$key] = $data;
|
156 |
+
}
|
157 |
+
|
158 |
+
return $result;
|
159 |
+
}
|
160 |
+
|
161 |
+
function add_global_groups( $groups ) {
|
162 |
+
if ( ! is_array( $groups ) )
|
163 |
+
$groups = (array) $groups;
|
164 |
+
|
165 |
+
$this->global_groups = array_merge( $this->global_groups, $groups );
|
166 |
+
$this->global_groups = array_unique( $this->global_groups );
|
167 |
+
}
|
168 |
+
|
169 |
+
function add_non_persistent_groups( $groups ) {
|
170 |
+
if ( ! is_array( $groups ) )
|
171 |
+
$groups = (array) $groups;
|
172 |
+
|
173 |
+
$this->no_mc_groups = array_merge( $this->no_mc_groups, $groups );
|
174 |
+
$this->no_mc_groups = array_unique( $this->no_mc_groups );
|
175 |
+
}
|
176 |
+
|
177 |
+
function incr( $id, $n = 1, $group = 'default' ) {
|
178 |
+
$key = $this->key( $id, $group );
|
179 |
+
$mc =& $this->get_mc( $group );
|
180 |
+
$this->cache[ $key ] = $mc->increment( $key, $n );
|
181 |
+
return $this->cache[ $key ];
|
182 |
+
}
|
183 |
+
|
184 |
+
function decr( $id, $n = 1, $group = 'default' ) {
|
185 |
+
$key = $this->key( $id, $group );
|
186 |
+
$mc =& $this->get_mc( $group );
|
187 |
+
$this->cache[ $key ] = $mc->decrement( $key, $n );
|
188 |
+
return $this->cache[ $key ];
|
189 |
+
}
|
190 |
+
|
191 |
+
function close() {
|
192 |
+
// Silence is Golden.
|
193 |
+
}
|
194 |
+
|
195 |
+
function delete( $id, $group = 'default' ) {
|
196 |
+
$key = $this->key( $id, $group );
|
197 |
+
|
198 |
+
if ( in_array( $group, $this->no_mc_groups ) ) {
|
199 |
+
unset( $this->cache[$key] );
|
200 |
+
return true;
|
201 |
+
}
|
202 |
+
|
203 |
+
$mc =& $this->get_mc( $group );
|
204 |
+
|
205 |
+
$result = $mc->delete( $key );
|
206 |
+
|
207 |
+
@ ++$this->stats['delete'];
|
208 |
+
$this->group_ops[$group][] = "delete $id";
|
209 |
+
|
210 |
+
if ( false !== $result )
|
211 |
+
unset( $this->cache[$key] );
|
212 |
+
|
213 |
+
return $result;
|
214 |
+
}
|
215 |
+
|
216 |
+
function flush() {
|
217 |
+
// Don't flush if multi-blog.
|
218 |
+
if ( function_exists( 'is_site_admin' ) || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) )
|
219 |
+
return true;
|
220 |
+
|
221 |
+
$ret = true;
|
222 |
+
foreach ( array_keys( $this->mc ) as $group )
|
223 |
+
$ret &= $this->mc[$group]->flush();
|
224 |
+
return $ret;
|
225 |
+
}
|
226 |
+
|
227 |
+
function get( $id, $group = 'default' ) {
|
228 |
+
$key = $this->key( $id, $group );
|
229 |
+
$mc =& $this->get_mc( $group );
|
230 |
+
|
231 |
+
if ( isset( $this->cache[$key] ) ) {
|
232 |
+
if ( is_object( $this->cache[$key] ) )
|
233 |
+
$value = clone $this->cache[$key];
|
234 |
+
else
|
235 |
+
$value = $this->cache[$key];
|
236 |
+
} else if ( in_array( $group, $this->no_mc_groups ) ) {
|
237 |
+
$this->cache[$key] = $value = false;
|
238 |
+
} else {
|
239 |
+
$value = $mc->get( $key );
|
240 |
+
if ( empty( $value ) || ( is_integer( $value ) && -1 == $value ) )
|
241 |
+
$value = false;
|
242 |
+
$this->cache[$key] = $value;
|
243 |
+
}
|
244 |
+
|
245 |
+
@ ++$this->stats['get'];
|
246 |
+
$this->group_ops[$group][] = "get $id";
|
247 |
+
|
248 |
+
if ( 'checkthedatabaseplease' === $value ) {
|
249 |
+
unset( $this->cache[$key] );
|
250 |
+
$value = false;
|
251 |
+
}
|
252 |
+
|
253 |
+
return $value;
|
254 |
+
}
|
255 |
+
|
256 |
+
function get_multi( $keys, $group = 'default' ) {
|
257 |
+
$return = array();
|
258 |
+
$gets = array();
|
259 |
+
foreach ( $keys as $i => $values ) {
|
260 |
+
$mc =& $this->get_mc( $group );
|
261 |
+
$values = (array) $values;
|
262 |
+
if ( empty( $values[1] ) )
|
263 |
+
$values[1] = 'default';
|
264 |
+
|
265 |
+
list( $id, $group ) = (array) $values;
|
266 |
+
$key = $this->key( $id, $group );
|
267 |
+
|
268 |
+
if ( isset( $this->cache[$key] ) ) {
|
269 |
+
|
270 |
+
if ( is_object( $this->cache[$key] ) )
|
271 |
+
$return[$key] = clone $this->cache[$key];
|
272 |
+
else
|
273 |
+
$return[$key] = $this->cache[$key];
|
274 |
+
|
275 |
+
} else if ( in_array( $group, $this->no_mc_groups ) ) {
|
276 |
+
$return[$key] = false;
|
277 |
+
|
278 |
+
} else {
|
279 |
+
$gets[$key] = $key;
|
280 |
+
}
|
281 |
+
}
|
282 |
+
|
283 |
+
if ( !empty( $gets ) ) {
|
284 |
+
$results = $mc->getMulti( $gets, $null, Memcached::GET_PRESERVE_ORDER );
|
285 |
+
$joined = array_combine( array_keys( $gets ), array_values( $results ) );
|
286 |
+
$return = array_merge( $return, $joined );
|
287 |
+
}
|
288 |
+
|
289 |
+
@ ++$this->stats['get_multi'];
|
290 |
+
$this->group_ops[$group][] = "get_multi $id";
|
291 |
+
$this->cache = array_merge( $this->cache, $return );
|
292 |
+
return array_values( $return );
|
293 |
+
}
|
294 |
+
|
295 |
+
function key( $key, $group ) {
|
296 |
+
if ( empty( $group ) )
|
297 |
+
$group = 'default';
|
298 |
+
|
299 |
+
if ( false !== array_search( $group, $this->global_groups ) )
|
300 |
+
$prefix = $this->global_prefix;
|
301 |
+
else
|
302 |
+
$prefix = $this->blog_prefix;
|
303 |
+
|
304 |
+
return preg_replace( '/\s+/', '', WP_CACHE_KEY_SALT . "$prefix$group:$key" );
|
305 |
+
}
|
306 |
+
|
307 |
+
function replace( $id, $data, $group = 'default', $expire = 0 ) {
|
308 |
+
$key = $this->key( $id, $group );
|
309 |
+
$expire = ( $expire == 0) ? $this->default_expiration : $expire;
|
310 |
+
$mc =& $this->get_mc( $group );
|
311 |
+
|
312 |
+
if ( is_object( $data ) )
|
313 |
+
$data = clone $data;
|
314 |
+
|
315 |
+
$result = $mc->replace( $key, $data, $expire );
|
316 |
+
if ( false !== $result )
|
317 |
+
$this->cache[$key] = $data;
|
318 |
+
return $result;
|
319 |
+
}
|
320 |
+
|
321 |
+
function set( $id, $data, $group = 'default', $expire = 0 ) {
|
322 |
+
$key = $this->key( $id, $group );
|
323 |
+
if ( isset( $this->cache[$key] ) && ( 'checkthedatabaseplease' === $this->cache[$key] ) )
|
324 |
+
return false;
|
325 |
+
|
326 |
+
if ( is_object( $data) )
|
327 |
+
$data = clone $data;
|
328 |
+
|
329 |
+
$this->cache[$key] = $data;
|
330 |
+
|
331 |
+
if ( in_array( $group, $this->no_mc_groups ) )
|
332 |
+
return true;
|
333 |
+
|
334 |
+
$expire = ( $expire == 0 ) ? $this->default_expiration : $expire;
|
335 |
+
$mc =& $this->get_mc( $group );
|
336 |
+
$result = $mc->set( $key, $data, $expire );
|
337 |
+
|
338 |
+
return $result;
|
339 |
+
}
|
340 |
+
|
341 |
+
function set_multi( $items, $expire = 0, $group = 'default' ) {
|
342 |
+
$sets = array();
|
343 |
+
$mc =& $this->get_mc( $group );
|
344 |
+
$expire = ( $expire == 0 ) ? $this->default_expiration : $expire;
|
345 |
+
|
346 |
+
foreach ( $items as $i => $item ) {
|
347 |
+
if ( empty( $item[2] ) )
|
348 |
+
$item[2] = 'default';
|
349 |
+
|
350 |
+
list( $id, $data, $group ) = $item;
|
351 |
+
|
352 |
+
$key = $this->key( $id, $group );
|
353 |
+
if ( isset( $this->cache[$key] ) && ( 'checkthedatabaseplease' === $this->cache[$key] ) )
|
354 |
+
continue;
|
355 |
+
|
356 |
+
if ( is_object( $data) )
|
357 |
+
$data = clone $data;
|
358 |
+
|
359 |
+
$this->cache[$key] = $data;
|
360 |
+
|
361 |
+
if ( in_array( $group, $this->no_mc_groups ) )
|
362 |
+
continue;
|
363 |
+
|
364 |
+
$sets[$key] = $data;
|
365 |
+
}
|
366 |
+
|
367 |
+
if ( !empty( $sets ) )
|
368 |
+
$mc->setMulti( $sets, $expire );
|
369 |
+
}
|
370 |
+
|
371 |
+
function colorize_debug_line( $line ) {
|
372 |
+
$colors = array(
|
373 |
+
'get' => 'green',
|
374 |
+
'set' => 'purple',
|
375 |
+
'add' => 'blue',
|
376 |
+
'delete'=> 'red'
|
377 |
+
);
|
378 |
+
|
379 |
+
$cmd = substr( $line, 0, strpos( $line, ' ' ) );
|
380 |
+
|
381 |
+
$cmd2 = "<span style='color:{$colors[$cmd]}'>$cmd</span>";
|
382 |
+
|
383 |
+
return $cmd2 . substr( $line, strlen( $cmd ) ) . "\n";
|
384 |
+
}
|
385 |
+
|
386 |
+
function stats() {
|
387 |
+
echo "<p>\n";
|
388 |
+
foreach ( $this->stats as $stat => $n ) {
|
389 |
+
echo "<strong>$stat</strong> $n";
|
390 |
+
echo "<br/>\n";
|
391 |
+
}
|
392 |
+
echo "</p>\n";
|
393 |
+
echo "<h3>Memcached:</h3>";
|
394 |
+
foreach ( $this->group_ops as $group => $ops ) {
|
395 |
+
if ( !isset( $_GET['debug_queries'] ) && 500 < count( $ops ) ) {
|
396 |
+
$ops = array_slice( $ops, 0, 500 );
|
397 |
+
echo "<big>Too many to show! <a href='" . add_query_arg( 'debug_queries', 'true' ) . "'>Show them anyway</a>.</big>\n";
|
398 |
+
}
|
399 |
+
echo "<h4>$group commands</h4>";
|
400 |
+
echo "<pre>\n";
|
401 |
+
$lines = array();
|
402 |
+
foreach ( $ops as $op ) {
|
403 |
+
$lines[] = $this->colorize_debug_line( $op );
|
404 |
+
}
|
405 |
+
print_r( $lines );
|
406 |
+
echo "</pre>\n";
|
407 |
+
}
|
408 |
+
|
409 |
+
if ( !empty( $this->debug ) && $this->debug )
|
410 |
+
var_dump( $this->memcache_debug );
|
411 |
+
}
|
412 |
+
|
413 |
+
function &get_mc( $group ) {
|
414 |
+
if ( isset( $this->mc[$group] ) )
|
415 |
+
return $this->mc[$group];
|
416 |
+
return $this->mc['default'];
|
417 |
+
}
|
418 |
+
|
419 |
+
function WP_Object_Cache() {
|
420 |
+
|
421 |
+
$memcached_servers = array(
|
422 |
+
'default' => array(
|
423 |
+
'@changedefaults@'
|
424 |
+
)
|
425 |
+
);
|
426 |
+
|
427 |
+
if ( isset( $memcached_servers ) )
|
428 |
+
$buckets = $memcached_servers;
|
429 |
+
else
|
430 |
+
$buckets = array( '127.0.0.1' );
|
431 |
+
|
432 |
+
reset( $buckets );
|
433 |
+
if ( is_int( key( $buckets ) ) )
|
434 |
+
$buckets = array( 'default' => $buckets );
|
435 |
+
|
436 |
+
foreach ( $buckets as $bucket => $servers ) {
|
437 |
+
$this->mc[$bucket] = new Memcached();
|
438 |
+
|
439 |
+
$instances = array();
|
440 |
+
foreach ( $servers as $server ) {
|
441 |
+
@list( $node, $port ) = explode( ':', $server );
|
442 |
+
if ( empty( $port ) )
|
443 |
+
$port = ini_get( 'memcache.default_port' );
|
444 |
+
$port = intval( $port );
|
445 |
+
if ( !$port )
|
446 |
+
$port = 11211;
|
447 |
+
|
448 |
+
$instances[] = array( $node, $port, 1 );
|
449 |
+
}
|
450 |
+
$this->mc[$bucket]->addServers( $instances );
|
451 |
+
}
|
452 |
+
|
453 |
+
global $blog_id, $table_prefix;
|
454 |
+
$this->global_prefix = '';
|
455 |
+
$this->blog_prefix = '';
|
456 |
+
if ( function_exists( 'is_multisite' ) ) {
|
457 |
+
$this->global_prefix = ( is_multisite() || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) ) ? '' : $table_prefix;
|
458 |
+
$this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':';
|
459 |
+
}
|
460 |
+
|
461 |
+
$this->cache_hits =& $this->stats['get'];
|
462 |
+
$this->cache_misses =& $this->stats['add'];
|
463 |
+
}
|
464 |
+
}
|
465 |
+
|
466 |
+
}
|
readme.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
=== SG CachePress ===
|
2 |
-
Contributors: Hristo Sg
|
3 |
Tags: nginx, caching, speed, memcache, memcached, performance, siteground, nginx, supercacher
|
4 |
Requires at least: 3.0.1
|
5 |
Tested up to: 4.3
|
1 |
=== SG CachePress ===
|
2 |
+
Contributors: Hristo Sg, danielkanchev
|
3 |
Tags: nginx, caching, speed, memcache, memcached, performance, siteground, nginx, supercacher
|
4 |
Requires at least: 3.0.1
|
5 |
Tested up to: 4.3
|
sg-cachepress.php
CHANGED
@@ -9,7 +9,7 @@
|
|
9 |
* @wordpress-plugin
|
10 |
* Plugin Name: SG CachePress
|
11 |
* Description: Through the settings of this plugin you can manage how your Wordpress interracts with NGINX and Memcached.
|
12 |
-
* Version: 2.2.
|
13 |
* Author: SiteGround
|
14 |
* Text Domain: sg-cachepress
|
15 |
* Domain Path: /languages
|
@@ -38,6 +38,7 @@ add_action( 'admin_init', array('SG_CachePress','admin_init_cachepress') );
|
|
38 |
|
39 |
add_action( 'init', 'disable_other_caching_plugins' );
|
40 |
|
|
|
41 |
/**
|
42 |
* Disables Other Caching Plugins if SG SuperCacher is enabled
|
43 |
*/
|
@@ -61,11 +62,11 @@ function sg_cachepress_start() {
|
|
61 |
$sg_cachepress_admin, $sg_cachepress_supercacher;
|
62 |
|
63 |
$sg_cachepress_options = new SG_CachePress_Options;
|
64 |
-
$sg_cachepress = new SG_CachePress( $sg_cachepress_options );
|
65 |
$sg_cachepress_environment = new SG_CachePress_Environment( $sg_cachepress_options );
|
66 |
$sg_cachepress_admin = new SG_CachePress_Admin( $sg_cachepress_options );
|
67 |
$sg_cachepress_memcache = new SG_CachePress_Memcache( $sg_cachepress_options, $sg_cachepress_environment );
|
68 |
$sg_cachepress_supercacher = new SG_CachePress_Supercacher( $sg_cachepress_options, $sg_cachepress_environment );
|
|
|
69 |
|
70 |
$sg_cachepress->run();
|
71 |
$sg_cachepress_admin->run();
|
9 |
* @wordpress-plugin
|
10 |
* Plugin Name: SG CachePress
|
11 |
* Description: Through the settings of this plugin you can manage how your Wordpress interracts with NGINX and Memcached.
|
12 |
+
* Version: 2.2.9
|
13 |
* Author: SiteGround
|
14 |
* Text Domain: sg-cachepress
|
15 |
* Domain Path: /languages
|
38 |
|
39 |
add_action( 'init', 'disable_other_caching_plugins' );
|
40 |
|
41 |
+
|
42 |
/**
|
43 |
* Disables Other Caching Plugins if SG SuperCacher is enabled
|
44 |
*/
|
62 |
$sg_cachepress_admin, $sg_cachepress_supercacher;
|
63 |
|
64 |
$sg_cachepress_options = new SG_CachePress_Options;
|
|
|
65 |
$sg_cachepress_environment = new SG_CachePress_Environment( $sg_cachepress_options );
|
66 |
$sg_cachepress_admin = new SG_CachePress_Admin( $sg_cachepress_options );
|
67 |
$sg_cachepress_memcache = new SG_CachePress_Memcache( $sg_cachepress_options, $sg_cachepress_environment );
|
68 |
$sg_cachepress_supercacher = new SG_CachePress_Supercacher( $sg_cachepress_options, $sg_cachepress_environment );
|
69 |
+
$sg_cachepress = new SG_CachePress( $sg_cachepress_options);
|
70 |
|
71 |
$sg_cachepress->run();
|
72 |
$sg_cachepress_admin->run();
|
views/sg-cache.php
CHANGED
@@ -73,4 +73,4 @@
|
|
73 |
<div class="clr"></div>
|
74 |
</div>
|
75 |
</div>
|
76 |
-
</div>
|
73 |
<div class="clr"></div>
|
74 |
</div>
|
75 |
</div>
|
76 |
+
</div>
|