public function testProxiesCallsOnCacheMiss()
 {
     $endpoint = $this->provider->getEndpoint('s3', 'us-east-1');
     $this->assertInstanceOf('Aws\\Common\\Region\\Endpoint', $endpoint);
     $this->assertSame($endpoint, $this->cache->fetch('s3_us-east-1'));
     $this->assertSame($endpoint, $this->provider->getEndpoint('s3', 'us-east-1'));
 }
 public function fetch($id)
 {
     $this->fetchHasBeenCalled = true;
     $this->callToFetchCount++;
     $this->id = $id;
     $data = $this->cacheProvider->fetch($id);
     return $data;
 }
Exemple #3
0
 /**
  *
  * @return MetadataBag
  */
 public function getMetadatas()
 {
     $key = realpath($this->file);
     if ($this->cache->contains($key)) {
         return $this->cache->fetch($key);
     }
     $metadatas = $this->parser->ParseMetadatas();
     $this->cache->save($key, $metadatas);
     return $metadatas;
 }
 /**
  * Retrieve Salesforce access token.
  *
  * @param Credentials $credentials
  * @return AccessToken
  */
 public function getToken(Credentials $credentials)
 {
     $cacheKey = $this->getCacheKey($credentials);
     if (!$this->cache->contains($cacheKey)) {
         $token = $this->tokenProvider->getToken($credentials);
         $this->cache->save($cacheKey, $token);
         return $token;
     }
     return $this->cache->fetch($cacheKey);
 }
 public function testGetStructures()
 {
     $cache = new ArrayCache();
     $structures = [$this->generateStructure('t1', 'MyBundle:default:t1'), $this->generateStructure('t2', 'MyBundle:default:t2'), $this->generateStructure('t3', 'MyBundle:default:t3')];
     $theme = $this->prophesize('Sulu\\Component\\Webspace\\Theme');
     $theme->getKey()->willReturn('test');
     $webspace = $this->prophesize('Sulu\\Component\\Webspace\\Webspace');
     $webspace->getTheme()->willReturn($theme->reveal());
     $twigLoader = $this->prophesize('\\Twig_LoaderInterface');
     $twigLoader->getSource('MyBundle:default:t1.html.twig')->willThrow(new \Twig_Error_Loader('Missing template'));
     $twigLoader->getSource('MyBundle:default:t2.html.twig')->shouldBeCalled();
     $twigLoader->getSource('MyBundle:default:t3.html.twig')->willThrow(new \Twig_Error_Loader('Missing template'));
     $twig = $this->prophesize('\\Twig_Environment');
     $twig->getLoader()->willReturn($twigLoader->reveal());
     $structureManager = $this->prophesize('Sulu\\Component\\Content\\Compat\\StructureManagerInterface');
     $structureManager->getStructures()->willReturn($structures);
     $webspaceManager = $this->prophesize('Sulu\\Component\\Webspace\\Manager\\WebspaceManagerInterface');
     $webspaceManager->findWebspaceByKey('sulu_io')->willReturn($webspace->reveal());
     $activeTheme = $this->prophesize('Liip\\ThemeBundle\\ActiveTheme');
     $activeTheme->getName()->willReturn('before');
     $activeTheme->setName('test')->shouldBeCalled();
     $activeTheme->setName('before')->shouldBeCalled();
     $structureProvider = new WebspaceStructureProvider($twig->reveal(), $structureManager->reveal(), $webspaceManager->reveal(), $activeTheme->reveal(), $cache);
     $result = $structureProvider->getStructures('sulu_io');
     $this->assertCount(1, $result);
     $this->assertEquals($structures[1], $result[0]);
     $this->assertTrue($cache->contains('sulu_io'));
     $this->assertEquals(['t2'], $cache->fetch('sulu_io'));
 }
 function testKeysDoNotInterfere()
 {
     $cache = new ArrayCache();
     $ns = new CacheNamespace('foo', $cache);
     $ns->save('foo', 'bar');
     $this->assertFalse($cache->fetch('foo'));
     $this->assertEquals('bar', $ns->fetch('foo'));
 }
 public function testCache()
 {
     $cacheProvider = new ArrayCache();
     $loader = new JSONLoader(__DIR__ . '/../fixtures');
     $defaultConfig = $loader->getClassMetadataConfig('metadata.defaults');
     $lazyLoader = new LazyMetadataLoader($loader);
     $factory = new CacheMetadataFactory($lazyLoader, $cacheProvider, $defaultConfig);
     $class = 'a15l\\serialization\\metadata\\tests\\fixtures\\Dummy';
     $dummyData = $factory->getClassMetadata($class);
     $this->assertArrayHasKey('readonly', $dummyData);
     $rawData = json_decode(file_get_contents(__DIR__ . '../../fixtures' . DIRECTORY_SEPARATOR . 'a15l.serialization.metadata.tests.fixtures.Dummy.json'), true);
     $this->assertEquals(json_encode($rawData), json_encode($dummyData));
     $this->assertTrue($cacheProvider->contains('class-metadata::' . $class));
     $this->assertEquals(json_encode($rawData), json_encode($cacheProvider->fetch('class-metadata::' . $class)));
 }
 public function testGarbageCollectAll()
 {
     $ts = 0;
     $time = $this->getMock('\\MS\\Throttle\\Time');
     $time->expects($this->any())->method('getTimestamp')->will($this->returnCallback(function () use(&$ts) {
         return $ts;
     }));
     $cache = new ArrayCache();
     $throttle = new Throttle($cache, $time);
     $throttle->addInterval(100, 25);
     $ts = 100;
     $throttle->increment('id1');
     $throttle->increment('id2');
     $ts = 150;
     $throttle->increment('id1');
     $ts = 220;
     $throttle->increment('id1');
     $ts = 240;
     $throttle->increment('id1');
     $throttle->increment('id2');
     $throttle->garbageCollect();
     $this->assertCount(3, $cache->fetch('id1'));
     $this->assertCount(1, $cache->fetch('id2'));
 }
 /**
  * @Then /^failover status should be set to dont retry until some time in future$/
  */
 public function failoverStatusShouldBeSetToDontRetryUntilSomeTimeInFuture()
 {
     \assertTrue($this->cache->fetch($this->failoverStatusVar()) > time());
 }
 public function testHandles404RevalidationResponses()
 {
     $request = new Request('GET', 'http://foo.com');
     $request->setClient(new Client());
     $badResponse = new Response(404, array(), 'Oh no!');
     $badRequest = clone $request;
     $badRequest->setResponse($badResponse, true);
     $response = new Response(200, array(), 'foo');
     $plugin = new CachePlugin();
     $c = new ArrayCache();
     $c->save('foo', array(200, array(), 'foo'));
     $s = new DefaultCacheStorage(new DoctrineCacheAdapter($c));
     $k = new CallbackCacheKeyProvider(function () {
         return 'foo';
     });
     $rev = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\DefaultRevalidation')->setConstructorArgs(array($k, $s, $plugin))->setMethods(array('createRevalidationRequest'))->getMock();
     $rev->expects($this->once())->method('createRevalidationRequest')->will($this->returnValue($badRequest));
     try {
         $rev->revalidate($request, $response);
         $this->fail('Should have thrown an exception');
     } catch (BadResponseException $e) {
         $this->assertSame($badResponse, $e->getResponse());
         $this->assertFalse($c->fetch('foo'));
     }
 }
 public function fetch($id)
 {
     $this->fetchedIDs[$id] = true;
     return parent::fetch($id);
 }
 public function testWriteCleansInvalidFails()
 {
     $invalidTime = time() - 301;
     $c = new ArrayCache();
     $c->save('circuitbreaker_tests', ['failures' => [$invalidTime]]);
     $b = new CircuitBreaker('tests', $c);
     $b->failure();
     $this->assertTrue($b->isClosed());
     $this->assertCount(1, $c->fetch('circuitbreaker_tests')['failures']);
     $this->assertFalse(in_array($invalidTime, $c->fetch('circuitbreaker_tests')['failures']));
 }