1 | <?php |
||
19 | class CachingPool extends Pool |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * @var CacheInterface |
||
24 | */ |
||
25 | private $cache; |
||
26 | |||
27 | /** |
||
28 | * Cache TTL in seconds. |
||
29 | * |
||
30 | * @var int Default is 10 minutes |
||
31 | */ |
||
32 | private $ttl = 600; |
||
33 | |||
34 | |||
35 | /** |
||
36 | * @param array $nodeUrls |
||
37 | * @param CacheInterface|null $cache |
||
38 | * @param LoggerInterface|null $log |
||
39 | * |
||
40 | * @throws ConnectException |
||
41 | */ |
||
42 | public function __construct(array $nodeUrls = array(), CacheInterface $cache = null, LoggerInterface $log = null) |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Connect to a random node in the (cached) node list. |
||
55 | * |
||
56 | * @return DefaultStream Stream to a connected node. |
||
57 | * |
||
58 | * @throws ConnectException |
||
59 | */ |
||
60 | public function connect() |
||
83 | |||
84 | |||
85 | /** |
||
86 | * Return the internal node cache TTL. |
||
87 | * |
||
88 | * @return int |
||
89 | */ |
||
90 | public function getCacheTtl() |
||
94 | |||
95 | |||
96 | /** |
||
97 | * Set the internal node cache TTL. |
||
98 | * |
||
99 | * @param int $ttl |
||
100 | */ |
||
101 | public function setCacheTtl($ttl) |
||
105 | |||
106 | |||
107 | /** |
||
108 | * Update the node list using the HELLO command. |
||
109 | * |
||
110 | * @param string $key |
||
111 | * @param StreamInterface $stream |
||
112 | */ |
||
113 | private function updateNodes($key, StreamInterface $stream) |
||
127 | } |
||
128 |