/** * local save method, one end save ok is ok * * @param CacheItemInterface $item * @param string $function save or saveDeferred * @return bool * @access protected */ protected function protectedSave(CacheItemInterface $item, $function = 'save') { // write to both ? $func = $this->tester; $both = $func($item); // if $both is true, write to front $res1 = false; if ($both) { if ($this->front->{$function}($item)) { $res1 = true; // ok } else { $this->setError($this->front->getError(), $this->front->getErrorCode()); } } // always write to backend $res2 = false; if ($this->back->{$function}($item)) { $res2 = true; // ok } else { $this->setError($this->back->getError(), $this->back->getErrorCode()); } return $res1 || $res2 ? true : false; }
/** * {@inheritDoc} */ public function setDriver(DriverInterface $driver, $fallback = true) { // ping first if ($driver->ping()) { $this->driver = $driver; return; } // fallback if ($fallback) { // set to fallback driver $this->driver = $driver->getFallback(); // issue warning trigger_error(Message::get(Message::CACHE_FALLBACK_DRIVER, get_class($driver), get_class($this->driver)), E_USER_WARNING); } else { throw new InvalidArgumentException(Message::get(Message::CACHE_FAIL_DRIVER, get_class($driver)), Message::CACHE_FAIL_DRIVER); } }