*/ private array $deviceResults = []; public function __construct( CacheItemPoolInterface $psr6Cache ) { $this->psr6Cache = new ProxyAdapter($psr6Cache, 'device_detector.'); $this->dd = new \DeviceDetector\DeviceDetector(); } public function parse(string $userAgent): DeviceResult { $userAgentHash = md5($userAgent); if (isset($this->deviceResults[$userAgentHash])) { return $this->deviceResults[$userAgentHash]; } $cacheItem = $this->psr6Cache->getItem($userAgentHash); if (!$cacheItem->isHit()) { $this->dd->setUserAgent($userAgent); $this->dd->parse(); $cacheItem->set(DeviceResult::fromDeviceDetector($userAgent, $this->dd)); /** @noinspection SummerTimeUnsafeTimeManipulationInspection */ $cacheItem->expiresAfter(86400 * 7); $this->psr6Cache->saveDeferred($cacheItem); } $deviceResult = $cacheItem->get(); $this->deviceResults[$userAgentHash] = $deviceResult; return $deviceResult; } }