1
0
mirror of https://github.com/danog/dns.git synced 2024-11-26 20:14:51 +01:00

Merge branch 'master' of github.com:/amphp/dns

This commit is contained in:
Chris Wright 2014-11-27 12:19:43 +00:00
commit 56fc89cca8
2 changed files with 24 additions and 14 deletions

23
lib/CacheFactory.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace Amp\Dns;
use Amp\Dns\Cache\MemoryCache;
use Amp\Dns\Cache\APCCache;
class CacheFactory
{
/**
* Get an instance of the best available caching back-end that does not have any dependencies
*
* @return Cache
*/
public function select()
{
if (extension_loaded('apc') && ini_get("apc.enabled") && @apc_cache_info()) {
return new APCCache;
}
return new MemoryCache;
}
}

View File

@ -3,11 +3,8 @@
namespace Amp\Dns;
use Amp\Reactor;
use Amp\Success;
use Amp\Failure;
use Amp\Future;
use Amp\Dns\Cache\MemoryCache;
use Amp\Dns\Cache\APCCache;
class Client {
const OP_MS_REQUEST_TIMEOUT = 0b0001;
@ -104,17 +101,7 @@ class Client {
$this->reactor = $reactor ?: \Amp\reactor();
$this->requestBuilder = $requestBuilder ?: new RequestBuilder;
$this->responseInterpreter = $responseInterpreter ?: new ResponseInterpreter;
if (!$cache) {
if (extension_loaded('apc') && ini_get("apc.enabled") && @apc_cache_info()) {
$cache = new APCCache;
}
else {
$cache = new MemoryCache;
}
}
$this->cache = $cache;
$this->cache = $cache ?: (new CacheFactory)->select();
}
/**