/** * 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($this->_options['logPriority'], "Writing to cache failed."); } else { trigger_error("Writing to cache failed.", E_USER_NOTICE); } } self::$_cache->removeItem($id); return false; } return true; }
public function testRemoveItemReturnsFalseOnMissingItem() { $this->assertFalse($this->_storage->removeItem('missing')); }
/** * Clear the page item cache. * * @param int $pageNumber * @return Paginator */ public function clearPageItemCache($pageNumber = null) { if (!$this->_cacheEnabled()) { return $this; } if (null === $pageNumber) { self::$_cache->find(CacheAdapter::MATCH_TAGS_OR, array('tags' => array( $this->_getCacheInternalId() ))); $cacheIds = array(); while (($item = self::$_cache->fetch()) !== false) { $cacheIds[] = $item['key']; } foreach ($cacheIds as $id) { if (preg_match('|'.self::CACHE_TAG_PREFIX."(\d+)_.*|", $id, $page)) { self::$_cache->removeItem($this->_getCacheId($page[1])); } } } else { $cleanId = $this->_getCacheId($pageNumber); self::$_cache->removeItem($cleanId); } return $this; }