/** * Construct with configs/settings * * @param DriverInterface $frontDriver * @param DriverInterface $backDriver * @param array $configs object configs * @access public */ public function __construct(DriverInterface $frontDriver, DriverInterface $backDriver, array $configs = []) { // set configs parent::__construct($configs); // front driver, may use fallback if ($frontDriver->ping()) { $this->front = $frontDriver; } else { // set error $this->setError($frontDriver->getError(), $frontDriver->getErrorCode()); $this->front = $frontDriver->getFallback(); } // back driver, may use fallback if ($backDriver->ping()) { $this->back = $backDriver; } else { // set error $this->setError($backDriver->getError(), $backDriver->getErrorCode()); $this->back = $backDriver->getFallback(); } // default tester, will write item to both front/back cache if (!is_callable($this->tester)) { $this->tester = function () { return true; }; } }
/** * Construct with configs/settings * * @param array $configs (optional) object configs * @access public */ public function __construct(array $configs = []) { // parent constructor parent::__construct($configs); // default cache directory if (empty($this->dir_root)) { $this->dir_root = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'cache'; } // clean up $this->dir_root = rtrim($this->dir_root, " \t\r\n\v\\/"); // set error to trigger fallback driver if (!is_dir($this->dir_root) && !@mkdir($this->dir_root, 0777, true)) { // set error $this->setError(Message::get(Message::CACHE_FAIL_MKDIR, $this->dir_root), Message::CACHE_FAIL_MKDIR); } }