Skip to content
Snippets Groups Projects
Commit 030ee36b authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Merge branch 'feature/cache-resolvers' into 'master'

Feature/cache resolvers

See merge request !4
parents 41ba3ad4 38e0b4d3
No related branches found
No related tags found
1 merge request!4Feature/cache resolvers
Pipeline #5370 passed with warnings with stages
in 4 minutes and 53 seconds
......@@ -9,7 +9,7 @@
"require": {
"php": ">=5.5",
"psr/log": "^1.0.1",
"wpdesk/wp-cache": "^1.0",
"wpdesk/wp-cache": "dev-feature/cache-resolver-creator",
"wpdesk/wp-http-client": "^1.0",
"psr/simple-cache": "^1.0"
},
......
......@@ -4,6 +4,7 @@ namespace WPDesk\ApiClient\Client;
use Psr\SimpleCache\CacheInterface;
use WPDesk\Cache\CacheDispatcher;
use WPDesk\Cache\CacheInfoResolverCreator;
use WPDesk\Cache\CacheItemCreator;
use WPDesk\Cache\CacheItemVerifier;
use WPDesk\HttpClient\HttpClient;
......@@ -27,14 +28,29 @@ class CachedClient implements Client, CacheItemCreator, CacheItemVerifier
/**
* CachedClient constructor.
*
* @param Client $decorated Decorated client
* @param CacheInterface $cache
*/
public function __construct(Client $decorated, CacheInterface $cache)
{
$this->client = $decorated;
$this->cache = $cache;
$this->cacheDispatcher = new CacheDispatcher($cache, [new RequestCacheInfoResolver()]);
$this->cache = $cache;
$this->cacheDispatcher = new CacheDispatcher($cache, $this->getCacheInfoResolvers());
}
/**
* Get cache info resolvers.
*
* @return RequestCacheInfoResolver[]
*/
protected function getCacheInfoResolvers()
{
if ($this->client instanceof CacheInfoResolverCreator) {
return $this->client->createResolvers();
} else {
return [new RequestCacheInfoResolver()];
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment