Skip to content

Commit 07b3fbf

Browse files
committed
Allow for cache adapter injection
1 parent 62f6201 commit 07b3fbf

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/Resolver/Factory.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace React\Dns\Resolver;
44

55
use React\Cache\ArrayCache;
6+
use React\Cache\CacheInterface;
67
use React\Dns\Query\Executor;
78
use React\Dns\Query\CachedExecutor;
89
use React\Dns\Query\RecordCache;
@@ -21,10 +22,14 @@ public function create($nameserver, LoopInterface $loop)
2122
return new Resolver($nameserver, $executor);
2223
}
2324

24-
public function createCached($nameserver, LoopInterface $loop)
25+
public function createCached($nameserver, LoopInterface $loop, CacheInterface $cache = null)
2526
{
27+
if (!($cache instanceof CacheInterface)) {
28+
$cache = new ArrayCache();
29+
}
30+
2631
$nameserver = $this->addPortToServerIfMissing($nameserver);
27-
$executor = $this->createCachedExecutor($loop);
32+
$executor = $this->createCachedExecutor($loop, $cache);
2833

2934
return new Resolver($nameserver, $executor);
3035
}
@@ -39,9 +44,9 @@ protected function createRetryExecutor(LoopInterface $loop)
3944
return new RetryExecutor($this->createExecutor($loop));
4045
}
4146

42-
protected function createCachedExecutor(LoopInterface $loop)
47+
protected function createCachedExecutor(LoopInterface $loop, CacheInterface $cache)
4348
{
44-
return new CachedExecutor($this->createRetryExecutor($loop), new RecordCache(new ArrayCache()));
49+
return new CachedExecutor($this->createRetryExecutor($loop), new RecordCache($cache));
4550
}
4651

4752
protected function addPortToServerIfMissing($nameserver)

0 commit comments

Comments
 (0)