weblog-content /wp-content/plugins/w3-total-cache/lib/W3/Cache.php

Language PHP Lines 95
MD5 Hash aa28e74282a3703a933eecc177907e7a Estimated Cost $1,408 (why?)
Repository https://bitbucket.org/openfarmtech/weblog-content View Raw File View Project SPDX
 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
<?php

/**
 * W3 Cache class
 */

/**
 * W3 Cache engine types
 */
if (!defined('W3_CACHE_MEMCACHED')) {
    define('W3_CACHE_MEMCACHED', 'memcached');
}

if (!defined('W3_CACHE_APC')) {
    define('W3_CACHE_APC', 'apc');
}

if (!defined('W3_CACHE_EACCELERATOR')) {
    define('W3_CACHE_EACCELERATOR', 'eaccelerator');
}

if (!defined('W3_CACHE_XCACHE')) {
    define('W3_CACHE_XCACHE', 'xcache');
}

if (!defined('W3_CACHE_FILE')) {
    define('W3_CACHE_FILE', 'file');
}

if (!defined('W3_CACHE_FILE_PGCACHE')) {
    define('W3_CACHE_FILE_PGCACHE', 'file_pgcache');
}

/**
 * Class W3_Cache
 */
class W3_Cache
{
    /**
     * Returns cache engine instance
     *
     * @param string $engine
     * @param array $config
     * @return W3_Cache_Base
     */
    function &instance($engine, $config = array())
    {
        static $instances = array();
        
        $instance_key = sprintf('%s_%s', $engine, md5(serialize($config)));
        
        if (!isset($instances[$instance_key])) {
            switch ($engine) {
                case W3_CACHE_MEMCACHED:
                    require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php';
                    $instances[$instance_key] = & new W3_Cache_Memcached($config);
                    break;
                
                case W3_CACHE_APC:
                    require_once W3TC_LIB_W3_DIR . '/Cache/Apc.php';
                    $instances[$instance_key] = & new W3_Cache_Apc();
                    break;
                
                case W3_CACHE_EACCELERATOR:
                    require_once W3TC_LIB_W3_DIR . '/Cache/Eaccelerator.php';
                    $instances[$instance_key] = & new W3_Cache_Eaccelerator();
                    break;
                
                case W3_CACHE_XCACHE:
                    require_once W3TC_LIB_W3_DIR . '/Cache/Xcache.php';
                    $instances[$instance_key] = & new W3_Cache_Xcache();
                    break;
                
                case W3_CACHE_FILE:
                    require_once W3TC_LIB_W3_DIR . '/Cache/File.php';
                    $instances[$instance_key] = & new W3_Cache_File($config);
                    break;
                
                case W3_CACHE_FILE_PGCACHE:
                    require_once W3TC_LIB_W3_DIR . '/Cache/File/PgCache.php';
                    $instances[$instance_key] = & new W3_Cache_File_PgCache($config);
                    break;
                
                default:
                    trigger_error('Incorrect cache engine', E_USER_WARNING);
                    require_once W3TC_LIB_W3_DIR . '/Cache/Base.php';
                    $instances[$instance_key] = & new W3_Cache_Base();
                    break;
            }
        }
        
        return $instances[$instance_key];
    }
}
Back to Top