2023-06-05 11:23:16 +00:00
|
|
|
<?php
|
2023-12-08 23:23:32 +00:00
|
|
|
/**
|
|
|
|
* File: Cache.php
|
|
|
|
*
|
|
|
|
* @package W3TC
|
|
|
|
*/
|
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
namespace W3TC;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* W3 Cache class
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2023-12-08 23:23:32 +00:00
|
|
|
* Class: Cache
|
2023-06-05 11:23:16 +00:00
|
|
|
*/
|
|
|
|
class Cache {
|
|
|
|
/**
|
|
|
|
* Returns cache engine instance
|
|
|
|
*
|
2023-12-08 23:23:32 +00:00
|
|
|
* @param string $engine Engine key code.
|
|
|
|
* @param array $config Configuration.
|
2023-06-05 11:23:16 +00:00
|
|
|
* @return W3_Cache_Base
|
|
|
|
*/
|
2023-12-08 23:23:32 +00:00
|
|
|
public static function instance( $engine, $config = array() ) {
|
2023-06-05 11:23:16 +00:00
|
|
|
static $instances = array();
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
// Common configuration data.
|
|
|
|
if ( ! isset( $config['blog_id'] ) ) {
|
2023-06-05 11:23:16 +00:00
|
|
|
$config['blog_id'] = Util_Environment::blog_id();
|
2023-12-08 23:23:32 +00:00
|
|
|
}
|
2023-06-05 11:23:16 +00:00
|
|
|
|
|
|
|
$instance_key = sprintf( '%s_%s', $engine, md5( serialize( $config ) ) );
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
if ( ! isset( $instances[ $instance_key ] ) ) {
|
2023-06-05 11:23:16 +00:00
|
|
|
switch ( $engine ) {
|
2023-12-08 23:23:32 +00:00
|
|
|
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 );
|
2023-06-05 11:23:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
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;
|
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
case 'eaccelerator':
|
2023-12-08 23:23:32 +00:00
|
|
|
$engine_name = 'EAccelerator';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'redis':
|
|
|
|
$engine_name = 'Redis';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'xcache':
|
|
|
|
$engine_name = 'XCache';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'wincache':
|
|
|
|
$engine_name = 'WinCache';
|
2023-06-05 11:23:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'file':
|
2023-12-08 23:23:32 +00:00
|
|
|
if ( 'pgcache' === $module ) {
|
|
|
|
$engine_name = 'Disk: Basic';
|
|
|
|
} else {
|
|
|
|
$engine_name = 'Disk';
|
|
|
|
}
|
2023-06-05 11:23:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'file_generic':
|
2023-12-08 23:23:32 +00:00
|
|
|
$engine_name = 'Disk: Enhanced';
|
2023-06-05 11:23:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
case 'ftp':
|
|
|
|
$engine_name = 'Self-hosted / file transfer protocol upload';
|
2023-06-05 11:23:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
case 's3':
|
|
|
|
$engine_name = 'Amazon Simple Storage Service (S3)';
|
2023-06-05 11:23:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
case 's3_compatible':
|
|
|
|
$engine_name = 'S3 compatible';
|
2023-06-05 11:23:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
case 'cf':
|
|
|
|
$engine_name = 'Amazon Cloudfront';
|
2023-06-05 11:23:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
case 'google_drive':
|
|
|
|
$engine_name = 'Google Drive';
|
2023-06-05 11:23:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
case 'highwinds':
|
|
|
|
$engine_name = 'Highwinds';
|
2023-06-05 11:23:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
case 'cf2':
|
|
|
|
$engine_name = 'Amazon Cloudfront';
|
|
|
|
break;
|
2023-06-05 11:23:16 +00:00
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
case 'rscf':
|
|
|
|
$engine_name = 'Rackspace Cloud Files';
|
|
|
|
break;
|
2023-06-05 11:23:16 +00:00
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
case 'azure':
|
|
|
|
$engine_name = 'Microsoft Azure Storage';
|
|
|
|
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;
|
2023-06-05 11:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $engine_name;
|
|
|
|
}
|
|
|
|
}
|