예제 #1
0
    public function testClearAll()
    {
        $capabilities = $this->_storage->getCapabilities();
        if (!$capabilities->getClearAllNamespaces()) {
            $this->setExpectedException('Zend\Cache\Exception\ExceptionInterface');
            $this->_storage->clear(AdapterInterface::MATCH_ALL);
            return;
        }

        $items = array(
            'key1' => 'value1',
            'key2' => 'value2',
            'key3' => 'value3'
        );
        $namespaces = array('ns1', 'ns2');

        foreach ($namespaces as $ns) {
            $this->_options->setNamespace($ns);
            foreach ($items as $k => $v) {
                $this->assertTrue($this->_storage->setItem($ns.$k, $ns.$v));
            }
        }

        $this->assertTrue($this->_storage->clear(AdapterInterface::MATCH_ALL));

        // wait
        usleep($capabilities->getTtlPrecision() * 2000000);

        foreach ($namespaces as $ns) {
            $this->_options->setNamespace($ns);
            foreach ($items as $k => $v) {
                $this->assertFalse($this->_storage->hasItem($ns.$k));
            }
        }
    }
예제 #2
0
 /**
  * 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;
 }