This repository has been archived by the owner on Feb 23, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Cache.php
197 lines (156 loc) · 3.76 KB
/
Cache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
namespace W3TC;
/**
* W3 Cache class
*/
/**
* class Cache
*/
class Cache {
/**
* Returns cache engine instance
*
* @param string $engine
* @param array $config
* @return W3_Cache_Base
*/
static function instance( $engine, $config = array() ) {
static $instances = array();
// common configuration data
if ( !isset( $config['blog_id'] ) )
$config['blog_id'] = Util_Environment::blog_id();
$instance_key = sprintf( '%s_%s', $engine, md5( serialize( $config ) ) );
if ( !isset( $instances[$instance_key] ) ) {
switch ( $engine ) {
case 'apc':
if ( function_exists( 'apcu_store' ) )
$instances[$instance_key] = new Cache_Apcu( $config );
else if ( function_exists( 'apc_store' ) )
$instances[$instance_key] = new Cache_Apc( $config );
break;
case 'eaccelerator':
$instances[$instance_key] = new Cache_Eaccelerator( $config );
break;
case 'file':
$instances[$instance_key] = new Cache_File( $config );
break;
case 'file_generic':
$instances[$instance_key] = new Cache_File_Generic( $config );
break;
case 'memcached':
if ( class_exists( '\Memcached' ) ) {
$instances[$instance_key] = new Cache_Memcached( $config );
} elseif ( class_exists( '\Memcache' ) ) {
$instances[$instance_key] = new Cache_Memcache( $config );
}
break;
case 'redis':
$instances[$instance_key] = new Cache_Redis( $config );
break;
case 'wincache':
$instances[$instance_key] = new Cache_Wincache( $config );
break;
case 'xcache':
$instances[$instance_key] = new Cache_Xcache( $config );
break;
default:
trigger_error( 'Incorrect cache engine ' . $engine, E_USER_WARNING );
$instances[$instance_key] = new Cache_Base( $config );
break;
}
if ( !isset( $instances[$instance_key] ) ||
!$instances[$instance_key]->available() ) {
$instances[$instance_key] = new Cache_Base( $config );
}
}
return $instances[$instance_key];
}
/**
* Returns caching engine name
*
* @param unknown $engine
* @param unknown $module
*
* @return string
*/
static public function engine_name( $engine, $module = '' ) {
switch ( $engine ) {
case 'memcached':
if ( class_exists( 'Memcached' ) )
$engine_name = 'memcached';
else
$engine_name = 'memcache';
break;
case 'apc':
$engine_name = 'apc';
break;
case 'eaccelerator':
$engine_name = 'eaccelerator';
break;
case 'redis':
$engine_name = 'redis';
break;
case 'xcache':
$engine_name = 'xcache';
break;
case 'wincache':
$engine_name = 'wincache';
break;
case 'file':
if ( $module == 'pgcache' )
$engine_name = 'disk: basic';
else
$engine_name = 'disk';
break;
case 'file_generic':
$engine_name = 'disk: enhanced';
break;
case 'ftp':
$engine_name = 'self-hosted / file transfer protocol upload';
break;
case 's3':
$engine_name = 'amazon simple storage service (s3)';
break;
case 'cf':
$engine_name = 'amazon cloudfront';
break;
case 'google_drive':
$engine_name = 'google drive';
break;
case 'highwinds':
$engine_name = 'highwinds';
break;
case 'cf2':
$engine_name = 'amazon cloudfront';
break;
case 'rscf':
$engine_name = 'rackspace cloud files';
break;
case 'azure':
$engine_name = 'microsoft azure storage';
break;
case 'mirror':
$engine_name = 'mirror';
break;
case 'maxcdn':
$engine_name = 'maxcdn';
break;
case 'cotendo':
$engine_name = 'cotendo';
break;
case 'akamai':
$engine_name = 'akamai';
break;
case 'edgecast':
$engine_name = 'media template procdn / edgecast';
break;
case 'att':
$engine_name = 'at&t';
break;
default:
$engine_name = 'n/a';
break;
}
return $engine_name;
}
}