Ejemplo n.º 1
0
 public static function init($config)
 {
     self::$config = $config;
     if (!self::$config['enable']) {
         return;
     }
     if (isset($GLOBALS['iCache']['link'])) {
         self::$link = $GLOBALS['iCache']['link'];
         return self::$link;
     }
     self::$config['engine'] or self::$config['engine'] = 'file';
     self::$config['reset'] && (self::$link = null);
     self::connect();
     return self::$link;
 }
Ejemplo n.º 2
0
 public static function init($config)
 {
     self::$config = $config;
     if (!self::$config['enable']) {
         return;
     }
     if (isset($GLOBALS['iCache']['link'])) {
         self::$link = $GLOBALS['iCache']['link'];
         return self::$link;
     }
     self::$config['engine'] or self::$config['engine'] = 'file';
     self::$config['reset'] && (self::$link = null);
     if (self::$link === null) {
         switch (self::$config['engine']) {
             case 'memcached':
                 require iPHP_CORE . '/memcached.class.php';
                 $_servers = explode("\n", str_replace(array("\r", " "), "", self::$config['host']));
                 self::$link = new memcached_client(array('servers' => $_servers, 'compress_threshold' => 10240, 'persistant' => false, 'debug' => false, 'compress' => self::$config['compress']));
                 unset($_servers);
                 break;
             case 'redis':
                 require iPHP_CORE . '/redis.class.php';
                 list($hosts, $db) = explode('@', trim(self::$config['host']));
                 list($host, $port) = explode(':', $hosts);
                 if (strstr($hosts, 'unix:')) {
                     $host = $hosts;
                     $port = 0;
                 }
                 $db = (int) str_replace('db:', '', $db);
                 $db == '' && ($db = 1);
                 self::$link = new Redis_client(array('host' => $host, 'port' => $port, 'db' => $db, 'compress' => self::$config['compress']));
                 break;
             case 'file':
                 require iPHP_CORE . '/iFileCache.class.php';
                 list($dirs, $level) = explode(':', self::$config['host']);
                 $level or $level = 0;
                 self::$link = new iFC(array('dirs' => $dirs, 'level' => $level, 'compress' => self::$config['compress']));
                 break;
         }
         $GLOBALS['iCache']['link'] = self::$link;
     }
     return self::$link;
 }