Ejemplo n.º 1
0
 public function __construct($params = array())
 {
     parent::init($params);
     Logger::getInstance()->addGroup('cache' . $this->_name, 'Cache ' . $this->_name, true, true);
     if (!isset($params['path']) || !is_string($params['path'])) {
         throw new \Exception('Miss path parameter, or is invalid');
     }
     if (!is_dir($params['path'])) {
         if (!mkdir($params['path'], 0775, true)) {
             throw new \Exception('Error on creating "' . $params['path'] . '" directory');
         }
     }
     if (!is_writable($params['path'])) {
         throw new \Exception('Directory "' . $params['path'] . '" is not writable');
     }
     $this->_path = realpath($params['path']) . DS;
 }
Ejemplo n.º 2
0
 public function __construct($params = array())
 {
     if (!extension_loaded('apcu') && !extension_loaded('apc')) {
         throw new \Exception('Apcu extension not loaded try change your PHP configuration');
     }
     parent::init($params);
     Logger::getInstance()->addGroup('cache' . $this->_name, 'Cache ' . $this->_name, true, true);
     //create dynamic key and add to prefix (it's for multi applications)
     if (!file_exists(PATH_CACHE . $this->_name)) {
         $key = rand();
         $file = new \SplFileObject(PATH_CACHE . 'ApcuKey' . $this->_name, 'w+');
         if ($file->flock(LOCK_EX)) {
             $file->fwrite($key);
             $file->flock(LOCK_UN);
         }
         $this->_prefix .= $key;
     } else {
         $this->_prefix .= file_get_contents(PATH_CACHE . $this->_name);
     }
 }