/** * 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); }
/** * * @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; }
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')); }
public function testCache() { $cache = new ArrayCache(); $torInfo = new TorInfo($cache); $this->assertTrue($torInfo->torCheckIp('176.58.100.98')->count() == 2, "Tor exit node not detected"); $this->assertTrue($cache->contains('tuxcoder_tor_info_exit_addresses')); }
public function testClearCache() { $acl = $this->getAcl(0); $this->aclCache->putInCache($acl); $this->aclCache->clearCache(); $this->assertFalse($this->cacheProvider->contains('foo5_class')); $this->assertFalse($this->cacheProvider->contains('oid5')); }
public function testFetchPropagateToFastestCache() { $cache1 = new ArrayCache(); $cache2 = new ArrayCache(); $cache2->save('bar', 'value'); $chainCache = new ChainCache(array($cache1, $cache2)); $this->assertFalse($cache1->contains('bar')); $result = $chainCache->fetch('bar'); $this->assertEquals('value', $result); $this->assertTrue($cache2->contains('bar')); }
public function testGetCachedGeocodedData() { $address = 'Paris, France'; $coordinates = array('lat' => 48.857049, 'lng' => 2.35223); $delegate = $this->getMock('Geocoder\\Provider\\ProviderInterface'); $delegate->expects($this->once())->method('getGeocodedData')->with($address)->will($this->returnValue($coordinates)); $provider = new CacheProvider($cache = new ArrayCache(), $delegate); $provider->getGeocodedData($address); $provider->getGeocodedData($address); $this->assertTrue($cache->contains(crc32($address))); }
public function testCachedMetadataFromFactory() { $cache = new ArrayCache(); $this->factory = new ClassMetadataFactory($this->loader, $cache); $metadata = $this->factory->getClassMetadata('DMS\\Tests\\Dummy\\Classes\\AnnotatedClass'); $this->assertTrue($cache->contains(ltrim('DMS\\Tests\\Dummy\\Classes\\AnnotatedClass', '\\'))); //Get new Factory to retrieve from cache $this->factory = new ClassMetadataFactory($this->loader, $cache); $metadataCached = $this->factory->getClassMetadata('DMS\\Tests\\Dummy\\Classes\\AnnotatedClass'); $this->assertEquals($metadata, $metadataCached); }
/** * @covers Guzzle\Http\Plugin\CachePlugin::revalidate * @expectedException Guzzle\Http\Exception\BadResponseException */ public function testRemovesMissingEntitesFromCacheWhenRevalidating() { $server = $this->getServer(); $server->enqueue(array("HTTP/1.1 200 OK\r\nCache-Control: max-age=1000, no-cache\r\nContent-Length: 4\r\n\r\nData", "HTTP/1.1 404 NOT FOUND\r\nContent-Length: 0\r\n\r\n")); $plugin = new CachePlugin($this->adapter); $client = new Client($server->getUrl()); $client->getEventDispatcher()->addSubscriber($plugin); $request1 = $client->get('/'); $request1->send(); $this->assertTrue($this->cache->contains($plugin->getCacheKey($request1))); $client->get('/')->send(); }
public function testWithArrayCache() { $class = $this->getClass(); $className = get_class($class); $arrayCache = new ArrayCache(); $this->_standard = new Standard($this->getLoader(), $arrayCache); $classMetadata = $this->_standard->getClassMetadata($className); $this->assertTrue($arrayCache->contains($className)); $this->_standard = new Standard($this->getLoader(), $arrayCache); $cachedClassMetadata = $this->_standard->getCache()->fetch($className); $this->assertSame($classMetadata, $cachedClassMetadata); }
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 testHydrationCache() { $cache = new ArrayCache(); $dql = "SELECT u FROM Doctrine\\Tests\\Models\\Cms\\CmsUser u"; $users = $this->_em->createQuery($dql)->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache))->getResult(); $c = $this->getCurrentQueryCount(); $users = $this->_em->createQuery($dql)->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache))->getResult(); $this->assertEquals($c, $this->getCurrentQueryCount(), "Should not execute query. Its cached!"); $users = $this->_em->createQuery($dql)->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache))->getArrayResult(); $this->assertEquals($c + 1, $this->getCurrentQueryCount(), "Hydration is part of cache key."); $users = $this->_em->createQuery($dql)->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache))->getArrayResult(); $this->assertEquals($c + 1, $this->getCurrentQueryCount(), "Hydration now cached"); $users = $this->_em->createQuery($dql)->setHydrationCacheProfile(new QueryCacheProfile(null, 'cachekey', $cache))->getArrayResult(); $this->assertTrue($cache->contains('cachekey'), 'Explicit cache key'); $users = $this->_em->createQuery($dql)->setHydrationCacheProfile(new QueryCacheProfile(null, 'cachekey', $cache))->getArrayResult(); $this->assertEquals($c + 2, $this->getCurrentQueryCount(), "Hydration now cached"); }
/** * @Given /^failover status should be cleaned$/ */ public function failoverStatusShouldBeCleaned() { \assertFalse($this->cache->contains($this->failoverStatusVar())); }
public function contains($id) { $this->containsHasBeenCalled = true; $this->id = $id; return $this->cacheProvider->contains($id); }
public function testStatePersists() { $c = new ArrayCache(); $b = new CircuitBreaker('tests', $c); $b->failure(); $this->assertTrue($c->contains('circuitbreaker_tests')); $this->assertCount(1, $c->fetch('circuitbreaker_tests')['failures']); }