/** * Saves the given cache * Prevents broken cache when write_control is disabled and displays problems by log or error * * @param mixed $data * @param string $id * @return boolean Returns false when the cache has not been written */ protected function saveCache($data, $id) { if (self::$_cacheTags) { self::$_cache->setItem($id, $data, array('tags' => array($this->_options['tag']))); } else { self::$_cache->setItem($id, $data); } if (!self::$_cache->hasItem($id)) { if (!$this->_options['disableNotices']) { if ($this->_options['log']) { $this->_options['log']->log("Writing to cache failed.", $this->_options['logPriority']); } else { trigger_error("Writing to cache failed.", E_USER_NOTICE); } } self::$_cache->removeItem($id); return false; } return true; }
/** * Verifica se um item existe e está ativo no cache, identificado pela chave. * * @access public * @param string $key Chave de identificação do item do cache * @return boolean O item existe e está ativo no cache? */ public function verificarItem(string $key) : bool { return $this->adapter->hasItem($key); }
public function testHasItemWithNonReadable() { $this->assertTrue($this->_storage->setItem('key', 'value')); $this->_options->setReadable(false); $this->assertFalse($this->_storage->hasItem('key')); }