forked from aws/aws-sdk-php
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add credentials cache and wrap it around instance profiles in the pro…
…vider chain
- Loading branch information
Showing
8 changed files
with
288 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace Aws; | ||
|
||
use Doctrine\Common\Cache\Cache; | ||
|
||
class DoctrineCacheAdapter implements CacheInterface, Cache | ||
{ | ||
/** @var Cache */ | ||
private $cache; | ||
|
||
public function __construct(Cache $cache) | ||
{ | ||
$this->cache = $cache; | ||
} | ||
|
||
public function get($key) | ||
{ | ||
return $this->cache->fetch($key); | ||
} | ||
|
||
public function fetch($key) | ||
{ | ||
return $this->get($key); | ||
} | ||
|
||
public function set($key, $value, $ttl = 0) | ||
{ | ||
return $this->cache->save($key, $value, $ttl); | ||
} | ||
|
||
public function save($key, $value, $ttl = 0) | ||
{ | ||
return $this->set($key, $value, $ttl); | ||
} | ||
|
||
public function remove($key) | ||
{ | ||
return $this->cache->delete($key); | ||
} | ||
|
||
public function delete($key) | ||
{ | ||
return $this->remove($key); | ||
} | ||
|
||
public function contains($key) | ||
{ | ||
return $this->cache->contains($key); | ||
} | ||
|
||
public function getStats() | ||
{ | ||
return $this->cache->getStats(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
namespace Aws\Test; | ||
|
||
use Aws\CacheInterface; | ||
use Aws\DoctrineCacheAdapter; | ||
use Doctrine\Common\Cache\Cache; | ||
|
||
class DoctrineCacheAdapterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testProxiesCallsToDoctrine() | ||
{ | ||
$wrappedCache = $this->getMock(Cache::class); | ||
|
||
$wrappedCache->expects($this->once()) | ||
->method('fetch') | ||
->with('foo') | ||
->willReturn('bar'); | ||
$wrappedCache->expects($this->once()) | ||
->method('save') | ||
->with('foo', 'bar', 0) | ||
->willReturn(true); | ||
$wrappedCache->expects($this->once()) | ||
->method('delete') | ||
->with('foo') | ||
->willReturn(true); | ||
|
||
$cache = new DoctrineCacheAdapter($wrappedCache); | ||
$cache->set('foo', 'bar', 0); | ||
$cache->get('foo'); | ||
$cache->remove('foo'); | ||
} | ||
|
||
public function testAdaptsCacheToAwsAndDoctrine() | ||
{ | ||
$wrappedCache = $this->getMock(Cache::class); | ||
$cache = new DoctrineCacheAdapter($wrappedCache); | ||
|
||
$this->assertInstanceOf(Cache::class, $cache); | ||
$this->assertInstanceOf(CacheInterface::class, $cache); | ||
} | ||
} |