| Total Complexity | 8 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class WikiDomainLookup |
||
| 12 | { |
||
| 13 | /** @var GuzzleClient */ |
||
| 14 | private $guzzle; |
||
| 15 | |||
| 16 | /** @var CacheItemPoolInterface */ |
||
| 17 | private $cache; |
||
| 18 | |||
| 19 | private const CACHE_KEY = 'global-search-wikidomainlookup'; |
||
| 20 | |||
| 21 | /** @var string Duration of cache for lookup table, as accepted by DateInterval::createFromDateString() */ |
||
| 22 | private const CACHE_TIME = '10 hours'; |
||
| 23 | |||
| 24 | public function __construct(GuzzleClient $guzzle, CacheItemPoolInterface $cache) |
||
| 25 | { |
||
| 26 | $this->guzzle = $guzzle; |
||
| 27 | $this->cache = $cache; |
||
| 28 | } |
||
| 29 | |||
| 30 | public function load(): array |
||
| 31 | { |
||
| 32 | $cacheItem = $this->cache->getItem(self::CACHE_KEY); |
||
| 33 | $lookup = null; //$cacheItem->get(); |
||
| 34 | if ($lookup === null) { |
||
|
|
|||
| 35 | $lookup = $this->loadUncached(); |
||
| 36 | $cacheItem->set($lookup) |
||
| 37 | ->expiresAfter(\DateInterval::createFromDateString(self::CACHE_TIME)); |
||
| 38 | $this->cache->save($cacheItem); |
||
| 39 | } |
||
| 40 | return $lookup; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function loadUncached(): array |
||
| 66 | } |
||
| 67 | } |
||
| 68 |