-
Notifications
You must be signed in to change notification settings - Fork 85
/
Cache.php
224 lines (179 loc) · 4.52 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
/**
* File: Cache.php
*
* @package W3TC
*/
namespace W3TC;
/**
* W3 Cache class
*/
/**
* Class: Cache
*/
class Cache {
/**
* Returns cache engine instance
*
* @param string $engine Engine key code.
* @param array $config Configuration.
* @return W3_Cache_Base
*/
public 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 'nginx_memcached':
$instances[ $instance_key ] = new Cache_Nginx_Memcached( $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 ' . esc_html( $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 string $engine Engine key code.
* @param string $module Module.
*
* @return string
*/
public static function engine_name( $engine, $module = '' ) {
switch ( $engine ) {
case 'memcached':
if ( class_exists( 'Memcached' ) ) {
$engine_name = 'Memcached';
} else {
$engine_name = 'Memcache';
}
break;
case 'nginx_memcached':
$engine_name = 'Nginx + Memcached';
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 ( 'pgcache' === $module ) {
$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 's3_compatible':
$engine_name = 'S3 compatible';
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 'cloudfront':
$engine_name = 'Amazon CloudFront';
break;
case 'rscf':
$engine_name = 'Rackspace Cloud Files';
break;
case 'azure':
$engine_name = 'Microsoft Azure Storage';
break;
case 'azuremi':
$engine_name = 'Microsoft Azure Storage (Managed Identity)';
break;
case 'edgecast':
$engine_name = 'Media Template ProCDN / EdgeCast';
break;
case 'att':
$engine_name = 'AT&T';
break;
case 'rackspace_cdn':
$engine_name = 'Rackspace';
break;
case 'stackpath2':
$engine_name = 'StackPath';
break;
case 'bunnycdn':
$engine_name = 'Bunny CDN';
break;
case '':
$engine_name = __( 'None', 'w3-total-cache' );
break;
default:
$engine_name = $engine;
break;
}
return $engine_name;
}
}