public function save($id, $data, $lifeTime = null) { $this->saveHasBeenCalled = true; $this->id = $id; $this->data = $data; $this->lifeTime = $lifeTime; return $this->cacheProvider->save($id, $data, $lifeTime); }
/** * * @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 testContainsWhenStringExistsInCache() { $arrayCache = new ArrayCache(); $arrayCache->save("test", "string_test"); $cache = new DoctrineCacheProvider($arrayCache); $this->assertTrue($cache->contains("test")); }
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')); } }
/** * @return Exchanger */ protected function createExchanger() { $cache = new ArrayCache(); $cache->save(EuropeanCentralBank::URI, file_get_contents(__DIR__ . '/fixtures/eurofxref-daily.xml')); $exchanger = new Exchanger(new EuropeanCentralBank(new Downloader($cache))); return $exchanger; }
public function testGetCachedMetadata() { $metadata = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); $cache = new ArrayCache(); $cache->save(__NAMESPACE__ . '\\ChildEntity$CLASSMETADATA', $metadata); $this->cmf->setCacheDriver($cache); $loadedMetadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\ChildEntity'); $this->assertSame($loadedMetadata, $metadata); }
public function testWrapsMethods() { $a = new ArrayCache(); $a->save('foo', '123'); $c = new DoctrineCacheAdapter($a); $s = new DefaultCacheStorage($c, 100); $this->assertEquals('123', $s->fetch('foo')); $s->delete('foo'); $this->assertNotEquals('123', $s->fetch('foo')); }
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 testGetStructuresCached() { $cache = new ArrayCache(); $cache->save('sulu_io', ['t1', 't3']); $structures = [$this->generateStructure('t1', 'MyBundle:default:t1'), $this->generateStructure('t2', 'MyBundle:default:t2'), $this->generateStructure('t3', 'MyBundle:default:t3')]; $twig = $this->prophesize('\\Twig_Environment'); $twig->getLoader()->shouldNotBeCalled(); $structureManager = $this->prophesize('Sulu\\Component\\Content\\Compat\\StructureManagerInterface'); $structureManager->getStructures()->shouldNotBeCalled(); $structureManager->getStructure('t1')->willReturn($structures[0]); $structureManager->getStructure('t2')->shouldNotBeCalled(); $structureManager->getStructure('t3')->willReturn($structures[2]); $webspaceManager = $this->prophesize('Sulu\\Component\\Webspace\\Manager\\WebspaceManagerInterface'); $webspaceManager->findWebspaceByKey('sulu_io')->shouldNotBeCalled(); $activeTheme = $this->prophesize('Liip\\ThemeBundle\\ActiveTheme'); $activeTheme->getName()->shouldNotBeCalled(); $activeTheme->setName('test')->shouldNotBeCalled(); $activeTheme->setName('before')->shouldNotBeCalled(); $structureProvider = new WebspaceStructureProvider($twig->reveal(), $structureManager->reveal(), $webspaceManager->reveal(), $activeTheme->reveal(), $cache); $result = $structureProvider->getStructures('sulu_io'); $this->assertCount(2, $result); $this->assertEquals($structures[0]->getKey(), $result[0]->getKey()); $this->assertEquals($structures[2]->getKey(), $result[1]->getKey()); }
public function testCachedTokenDoNotPerformAditionalRequests() { $cache = new ArrayCache(); $cache->save(Client::TOKEN_KEY, 'foobar'); $this->client = new Client(new Credentials('123'), 'es', $cache); $history = new History(); $this->client->getEmitter()->attach($history); $subscriber = new Mock(); $this->client->getEmitter()->attach($subscriber); // Set mocked response $body = new Stream(fopen(__DIR__ . '/../dummy_response_data/getUsers.json', 'r')); $subscriber->addResponse(new Response(200, [], $body)); $this->client->getUsers(); $this->assertCount(1, $history); }
/** * @Given /^failover status is dont retry until some time in past$/ */ public function failoverStatusIsDontRetryUntilSomeTimeInPast() { $this->cache->save($this->failoverStatusVar(), time() - 100); }
/** * @dataProvider provideDataForEvictFromCacheByIdentity */ public function testEvictFromCacheByIdentity($expected, $identity) { $this->cacheProvider->save('foo_1', 's:4:test;'); $this->aclCache->evictFromCacheByIdentity($identity); $this->assertEquals($expected, $this->cacheProvider->contains('foo_1')); }
public function testEventsFireOpenToClosed() { $message = false; $c = new ArrayCache(); $c->save('circuitbreaker_tests', ['failures' => [time() - 10]]); $b = new CircuitBreaker('tests', $c); $b->setThreshold(1); $b->onChange(function ($previous, $new) use(&$message) { $message = $previous . ' -> ' . $new; }); $b->success(); $this->assertEquals('open -> closed', $message); }