/**
  * Tests a get() on the fast backend, with no hit on the consistent backend.
  */
 public function testGetDoesntHitConsistentBackend()
 {
     $consistent_cache = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
     $timestamp_cid = ChainedFastBackend::LAST_WRITE_TIMESTAMP_PREFIX . 'cache_foo';
     $timestamp_item = (object) array('cid' => $timestamp_cid, 'data' => time() - 60);
     $consistent_cache->expects($this->once())->method('get')->with($timestamp_cid)->will($this->returnValue($timestamp_item));
     $consistent_cache->expects($this->never())->method('getMultiple');
     $fast_cache = new MemoryBackend('foo');
     $fast_cache->set('foo', 'baz');
     $chained_fast_backend = new ChainedFastBackend($consistent_cache, $fast_cache, 'foo');
     $this->assertEquals('baz', $chained_fast_backend->get('foo')->data);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function reset()
 {
     $this->changelist = array(StorageInterface::DEFAULT_COLLECTION => $this->getEmptyChangelist());
     $this->sourceNames = $this->targetNames = array();
     // Reset the static configuration data caches.
     $this->sourceCacheStorage->deleteAll();
     $this->targetCacheStorage->deleteAll();
     return $this->createChangelist();
 }
Example #3
0
 /**
  * Tests that route caching works.
  */
 public function testRouteCaching()
 {
     $connection = Database::getConnection();
     $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, $this->cacheTagsInvalidator, 'test_routes');
     $this->fixtures->createTables($connection);
     $dumper = new MatcherDumper($connection, $this->state, 'test_routes');
     $dumper->addRoutes($this->fixtures->sampleRouteCollection());
     $dumper->addRoutes($this->fixtures->complexRouteCollection());
     $dumper->dump();
     // A simple path.
     $path = '/path/add/one';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/add/one:');
     $this->assertEqual('/path/add/one', $cache->data['path']);
     $this->assertEqual([], $cache->data['query']);
     $this->assertEqual(3, count($cache->data['routes']));
     // A path with query parameters.
     $path = '/path/add/one?foo=bar';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/add/one:foo=bar');
     $this->assertEqual('/path/add/one', $cache->data['path']);
     $this->assertEqual(['foo' => 'bar'], $cache->data['query']);
     $this->assertEqual(3, count($cache->data['routes']));
     // A path with placeholders.
     $path = '/path/1/one';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/1/one:');
     $this->assertEqual('/path/1/one', $cache->data['path']);
     $this->assertEqual([], $cache->data['query']);
     $this->assertEqual(2, count($cache->data['routes']));
     // A path with a path alias.
     /** @var \Drupal\Core\Path\AliasStorageInterface $path_storage */
     $path_storage = \Drupal::service('path.alias_storage');
     $path_storage->save('/path/add/one', '/path/add-one');
     /** @var \Drupal\Core\Path\AliasManagerInterface $alias_manager */
     $alias_manager = \Drupal::service('path.alias_manager');
     $alias_manager->cacheClear();
     $path = '/path/add-one';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/add-one:');
     $this->assertEqual('/path/add/one', $cache->data['path']);
     $this->assertEqual([], $cache->data['query']);
     $this->assertEqual(3, count($cache->data['routes']));
 }
Example #4
0
 /**
  * Test file storage on a cache hit in CachedStorage::read().
  */
 public function testReadNonExistentFileCached()
 {
     $name = 'config.does_not_exist';
     $cache = new MemoryBackend(__FUNCTION__);
     $cache->set($name, FALSE);
     $storage = $this->getMock('Drupal\\Core\\Config\\StorageInterface');
     $storage->expects($this->never())->method('read');
     $this->cacheFactory->expects($this->once())->method('get')->with('config')->will($this->returnValue($cache));
     $cachedStorage = new CachedStorage($storage, $this->cacheFactory);
     $this->assertFalse($cachedStorage->read($name));
 }