Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add PSR-16 support #97

Merged
merged 3 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"league/flysystem": "^1.0",
"psr/cache": "^1.0",
"cache/array-adapter": "^0.4 || ^0.5 || ^1.0",
"illuminate/cache": "^5.0"
"illuminate/cache": "^5.0",
"cache/simple-cache-bridge": "^0.1 || ^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -39,6 +40,7 @@
"doctrine/cache": "This library have a lot of ready-to-use cache storage (to be use with Kevinrob\\GuzzleCache\\Storage\\DoctrineCacheStorage)",
"league/flysystem": "To be use with Kevinrob\\GuzzleCache\\Storage\\FlysystemStorage",
"psr/cache": "To be use with Kevinrob\\GuzzleCache\\Storage\\Psr6CacheStorage",
"psr/simple-cache": "To be use with Kevinrob\\GuzzleCache\\Storage\\Psr16CacheStorage",
"laravel/framework": "To be use with Kevinrob\\GuzzleCache\\Storage\\LaravelCacheStorage"
}
}
48 changes: 48 additions & 0 deletions src/Storage/Psr16CacheStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Kevinrob\GuzzleCache\Storage;

use Kevinrob\GuzzleCache\CacheEntry;
use Psr\SimpleCache\CacheInterface;

class Psr16CacheStorage implements CacheStorageInterface
{
/**
* @var CacheInterface
*/
private $cache;

public function __construct(CacheInterface $cache)
{
$this->cache = $cache;
}

/**
* {@inheritdoc}
*/
public function fetch($key)
{
$data = $this->cache->get($key);
if ($data instanceof CacheEntry) {
return $data;
}

return null;
}

/**
* {@inheritdoc}
*/
public function save($key, CacheEntry $data)
{
$this->cache->set($key, $data);
}

/**
* {@inheritdoc}
*/
public function delete($key)
{
return $this->cache->delete($key);
}
}
3 changes: 3 additions & 0 deletions tests/PrivateCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kevinrob\GuzzleCache\Tests;

use Cache\Adapter\PHPArray\ArrayCachePool;
use Cache\Bridge\SimpleCache\SimpleCacheBridge;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\Common\Cache\ChainCache;
Expand All @@ -14,6 +15,7 @@
use Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage;
use Kevinrob\GuzzleCache\Storage\FlysystemStorage;
use Kevinrob\GuzzleCache\Storage\Psr6CacheStorage;
use Kevinrob\GuzzleCache\Storage\Psr16CacheStorage;
use Kevinrob\GuzzleCache\Storage\VolatileRuntimeStorage;
use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy;
use League\Flysystem\Adapter\Local;
Expand All @@ -31,6 +33,7 @@ public function testCacheProvider()
new DoctrineCacheStorage(new PhpFileCache($TMP_DIR)),
new FlysystemStorage(new Local($TMP_DIR)),
new Psr6CacheStorage(new ArrayCachePool()),
new Psr16CacheStorage(new SimpleCacheBridge(new ArrayCachePool())),
new CompressedDoctrineCacheStorage(new ArrayCache()),
new VolatileRuntimeStorage(),
];
Expand Down
3 changes: 3 additions & 0 deletions tests/PublicCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kevinrob\GuzzleCache\Tests;

use Cache\Adapter\PHPArray\ArrayCachePool;
use Cache\Bridge\SimpleCache\SimpleCacheBridge;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\Common\Cache\ChainCache;
Expand All @@ -18,6 +19,7 @@
use Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage;
use Kevinrob\GuzzleCache\Storage\FlysystemStorage;
use Kevinrob\GuzzleCache\Storage\Psr6CacheStorage;
use Kevinrob\GuzzleCache\Storage\Psr16CacheStorage;
use Kevinrob\GuzzleCache\Storage\VolatileRuntimeStorage;
use Kevinrob\GuzzleCache\Strategy\PublicCacheStrategy;
use League\Flysystem\Adapter\Local;
Expand Down Expand Up @@ -99,6 +101,7 @@ public function testCacheProvider()
new DoctrineCacheStorage(new PhpFileCache($TMP_DIR)),
new FlysystemStorage(new Local($TMP_DIR)),
new Psr6CacheStorage(new ArrayCachePool()),
new Psr16CacheStorage(new SimpleCacheBridge(new ArrayCachePool())),
new CompressedDoctrineCacheStorage(new ArrayCache()),
new VolatileRuntimeStorage(),
];
Expand Down