This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
forked from szepeviktor/w3-total-cache-fixed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cache.php
102 lines (85 loc) · 3.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
<?php
/**
* W3 Cache class
*/
/**
* W3 Cache engine types
*/
define('W3TC_CACHE_MEMCACHED', 'memcached');
define('W3TC_CACHE_REDIS','redis');
define('W3TC_CACHE_APC', 'apc');
define('W3TC_CACHE_APCU', 'apcu');
define('W3TC_CACHE_EACCELERATOR', 'eaccelerator');
define('W3TC_CACHE_XCACHE', 'xcache');
define('W3TC_CACHE_WINCACHE', 'wincache');
define('W3TC_CACHE_FILE', 'file');
define('W3TC_CACHE_FILE_GENERIC', 'file_generic');
/**
* Class W3_Cache
*/
class W3_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'] = w3_get_blog_id();
$instance_key = sprintf('%s_%s', $engine, md5(serialize($config)));
if (!isset($instances[$instance_key])) {
switch ($engine) {
case W3TC_CACHE_MEMCACHED:
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Memcached.php');
$instances[$instance_key] = new W3_Cache_Memcached($config);
break;
case W3TC_CACHE_REDIS:
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Redis.php');
$instances[$instance_key] = new W3_Cache_Redis($config);
break;
case W3TC_CACHE_APC:
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Apc.php');
$instances[$instance_key] = new W3_Cache_Apc($config);
break;
case W3TC_CACHE_APCU:
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Apcu.php');
$instances[$instance_key] = new W3_Cache_Apcu($config);
break;
case W3TC_CACHE_EACCELERATOR:
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Eaccelerator.php');
$instances[$instance_key] = new W3_Cache_Eaccelerator($config);
break;
case W3TC_CACHE_XCACHE:
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Xcache.php');
$instances[$instance_key] = new W3_Cache_Xcache($config);
break;
case W3TC_CACHE_WINCACHE:
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Wincache.php');
$instances[$instance_key] = new W3_Cache_Wincache($config);
break;
case W3TC_CACHE_FILE:
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/File.php');
$instances[$instance_key] = new W3_Cache_File($config);
break;
case W3TC_CACHE_FILE_GENERIC:
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/File/Generic.php');
$instances[$instance_key] = new W3_Cache_File_Generic($config);
break;
default:
trigger_error('Incorrect cache engine', E_USER_WARNING);
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Base.php');
$instances[$instance_key] = new W3_Cache_Base($config);
break;
}
if (!$instances[$instance_key]->available()) {
w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Base.php');
$instances[$instance_key] = new W3_Cache_Base($config);
}
}
return $instances[$instance_key];
}
}