PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/openfarmtech/weblog-content
PHP | 94 lines | 61 code | 17 blank | 16 comment | 8 complexity | aa28e74282a3703a933eecc177907e7a MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, AGPL-3.0, CC-BY-SA-3.0
  1. <?php
  2. /**
  3. * W3 Cache class
  4. */
  5. /**
  6. * W3 Cache engine types
  7. */
  8. if (!defined('W3_CACHE_MEMCACHED')) {
  9. define('W3_CACHE_MEMCACHED', 'memcached');
  10. }
  11. if (!defined('W3_CACHE_APC')) {
  12. define('W3_CACHE_APC', 'apc');
  13. }
  14. if (!defined('W3_CACHE_EACCELERATOR')) {
  15. define('W3_CACHE_EACCELERATOR', 'eaccelerator');
  16. }
  17. if (!defined('W3_CACHE_XCACHE')) {
  18. define('W3_CACHE_XCACHE', 'xcache');
  19. }
  20. if (!defined('W3_CACHE_FILE')) {
  21. define('W3_CACHE_FILE', 'file');
  22. }
  23. if (!defined('W3_CACHE_FILE_PGCACHE')) {
  24. define('W3_CACHE_FILE_PGCACHE', 'file_pgcache');
  25. }
  26. /**
  27. * Class W3_Cache
  28. */
  29. class W3_Cache
  30. {
  31. /**
  32. * Returns cache engine instance
  33. *
  34. * @param string $engine
  35. * @param array $config
  36. * @return W3_Cache_Base
  37. */
  38. function &instance($engine, $config = array())
  39. {
  40. static $instances = array();
  41. $instance_key = sprintf('%s_%s', $engine, md5(serialize($config)));
  42. if (!isset($instances[$instance_key])) {
  43. switch ($engine) {
  44. case W3_CACHE_MEMCACHED:
  45. require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php';
  46. $instances[$instance_key] = & new W3_Cache_Memcached($config);
  47. break;
  48. case W3_CACHE_APC:
  49. require_once W3TC_LIB_W3_DIR . '/Cache/Apc.php';
  50. $instances[$instance_key] = & new W3_Cache_Apc();
  51. break;
  52. case W3_CACHE_EACCELERATOR:
  53. require_once W3TC_LIB_W3_DIR . '/Cache/Eaccelerator.php';
  54. $instances[$instance_key] = & new W3_Cache_Eaccelerator();
  55. break;
  56. case W3_CACHE_XCACHE:
  57. require_once W3TC_LIB_W3_DIR . '/Cache/Xcache.php';
  58. $instances[$instance_key] = & new W3_Cache_Xcache();
  59. break;
  60. case W3_CACHE_FILE:
  61. require_once W3TC_LIB_W3_DIR . '/Cache/File.php';
  62. $instances[$instance_key] = & new W3_Cache_File($config);
  63. break;
  64. case W3_CACHE_FILE_PGCACHE:
  65. require_once W3TC_LIB_W3_DIR . '/Cache/File/PgCache.php';
  66. $instances[$instance_key] = & new W3_Cache_File_PgCache($config);
  67. break;
  68. default:
  69. trigger_error('Incorrect cache engine', E_USER_WARNING);
  70. require_once W3TC_LIB_W3_DIR . '/Cache/Base.php';
  71. $instances[$instance_key] = & new W3_Cache_Base();
  72. break;
  73. }
  74. }
  75. return $instances[$instance_key];
  76. }
  77. }