mirror of
https://github.com/danog/dns.git
synced 2024-11-27 04:24:48 +01:00
Merge branch 'master' of github.com:/amphp/dns
This commit is contained in:
commit
56fc89cca8
23
lib/CacheFactory.php
Normal file
23
lib/CacheFactory.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -3,11 +3,8 @@
|
|||||||
namespace Amp\Dns;
|
namespace Amp\Dns;
|
||||||
|
|
||||||
use Amp\Reactor;
|
use Amp\Reactor;
|
||||||
use Amp\Success;
|
|
||||||
use Amp\Failure;
|
use Amp\Failure;
|
||||||
use Amp\Future;
|
use Amp\Future;
|
||||||
use Amp\Dns\Cache\MemoryCache;
|
|
||||||
use Amp\Dns\Cache\APCCache;
|
|
||||||
|
|
||||||
class Client {
|
class Client {
|
||||||
const OP_MS_REQUEST_TIMEOUT = 0b0001;
|
const OP_MS_REQUEST_TIMEOUT = 0b0001;
|
||||||
@ -104,17 +101,7 @@ class Client {
|
|||||||
$this->reactor = $reactor ?: \Amp\reactor();
|
$this->reactor = $reactor ?: \Amp\reactor();
|
||||||
$this->requestBuilder = $requestBuilder ?: new RequestBuilder;
|
$this->requestBuilder = $requestBuilder ?: new RequestBuilder;
|
||||||
$this->responseInterpreter = $responseInterpreter ?: new ResponseInterpreter;
|
$this->responseInterpreter = $responseInterpreter ?: new ResponseInterpreter;
|
||||||
|
$this->cache = $cache ?: (new CacheFactory)->select();
|
||||||
if (!$cache) {
|
|
||||||
if (extension_loaded('apc') && ini_get("apc.enabled") && @apc_cache_info()) {
|
|
||||||
$cache = new APCCache;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$cache = new MemoryCache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->cache = $cache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user