Exemplo n.º 1
0
 private function cache_driver()
 {
     if (empty(self::$_cache_driver)) {
         require_once "class.basecache.php";
         try {
             self::$_cache_driver = CacheProviderFactory::get_provider('memcached');
         } catch (Exception $e) {
             # Memcached not supported.
             self::$_cache_driver = CacheProviderFactory::get_provider('memory');
         }
     }
     return self::$_cache_driver;
 }
Exemplo n.º 2
0
 /**
  *
  * METHODS
  *
  */
 public static function init()
 {
     if (defined('MG_CACHE_DIR')) {
         self::$cacheDir = WP_CONTENT_DIR . '/' . MG_CACHE_DIR . '/' . self::$cacheSubdir;
     } else {
         self::$cacheDir = WP_CONTENT_DIR . '/cache/' . self::$cacheSubdir;
     }
     $wpContentUrl = preg_replace('/(http|https):\\/\\/' . $_SERVER['HTTP_HOST'] . '\\/(.*)\\/wp-content/', '/wp-content', WP_CONTENT_URL);
     if (defined('MG_CACHE_PATH')) {
         self::$cachePath = $wpContentUrl . '/' . MG_CACHE_PATH . '/' . self::$cacheSubdir;
     } else {
         self::$cachePath = $wpContentUrl . '/cache/' . self::$cacheSubdir;
     }
     if (defined('MG_CACHE_EXTENSION')) {
         self::$fileExtension = MG_CACHE_EXTENSION;
     } else {
         self::$fileExtension = 'cache';
     }
     if (defined('MG_CACHE_DRIVER')) {
         self::$cacheDriver = CacheProviderFactory::build(MG_CACHE_DRIVER);
     }
     // ABSPATH won't work reliably if WP is installed in a subdirectory
     self::$webRoot = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . '/';
     if (empty(self::$webRoot)) {
         self::$webRoot = ABSPATH;
     }
     if (defined('MG_CACHE_DRIVER')) {
         self::$cacheDriver = CacheProviderFactory::build(MG_CACHE_DRIVER);
     } else {
         self::$cacheDriver = CacheProviderFactory::build('file');
     }
     // test that cache directory is writable (for windows and vagrant... which fail is_writable)
     try {
         $testFile = self::$cacheDir . '/__cache.txt';
         $fp = fopen($testFile, 'w');
         fwrite($fp, 'hello cache!');
         if (!file_exists($testFile)) {
             throw new \Exception();
         }
         MgAssetHelper::registerSettings();
         MgAssetHelper::registerFilters();
     } catch (\Exception $e) {
         add_action('admin_notices', array('MgAssetHelper', 'adminErrorNoticeCacheDirectoryWritable'));
     }
 }
Exemplo n.º 3
0
 public function cache_driver()
 {
     if (isset($this->cache_driver)) {
         return $this->cache_driver;
     }
     # Check for memcached enabled
     require_once "class.basecache.php";
     try {
         $this->cache_driver = CacheProviderFactory::get_provider('memcached');
     } catch (Exception $e) {
         # Memcached not supported.
         $this->cache_driver = CacheProviderFactory::get_provider('session');
     }
     return $this->cache_driver;
 }