sql = $sql; $this->cache = null; $this->cacheTime = null; $this->cacheKey = null; } public function withCache(CacheInterface $cache, string $cacheKey, int $cacheTime = 60): SqlStatement { $this->cache = $cache; $this->cacheTime = $cacheTime; $this->cacheKey = $cacheKey; return $this; } public function withoutCache() { $this->cache = null; $this->cacheTime = null; $this->cacheKey = null; } public function getSql(): string { return $this->sql; } public function getCache(): ?CacheInterface { return $this->cache; } public function getCacheTime(): ?int { return $this->cacheTime; } public function getCacheKey(): ?string { return $this->cacheKey; } public function getIterator(DbDriverInterface $dbDriver, ?array $param = [], int $preFetch = 0): GenericIterator { $cacheKey = ""; if (!empty($this->cache)) { ksort($param); $cacheKey = $this->cacheKey . ':' . md5(json_encode($param)); if ($this->cache->has($cacheKey)) { return (new ArrayDataset($this->cache->get($cacheKey)))->getIterator(); } } do { $lock = $this->mutexIsLocked($cacheKey); if ($lock !== false) { usleep(200); continue; } $this->mutexLock($cacheKey); try { $statement = $dbDriver->prepareStatement($this->sql, $param, $this->cachedStatement); $dbDriver->executeCursor($statement); $iterator = $dbDriver->getIterator($statement, preFetch: $preFetch); if (!empty($this->cache)) { $cachedItem = $iterator->toArray(); $this->cache->set($cacheKey, $cachedItem, $this->cacheTime); return (new ArrayDataset($cachedItem))->getIterator(); } return $iterator; } finally { $this->mutexRelease($cacheKey); } } while (true); } public function getScalar(DbDriverInterface $dbDriver, ?array $array = null): mixed { $stmt = $dbDriver->prepareStatement($this->sql, $array, $this->cachedStatement); $dbDriver->executeCursor($stmt); return $dbDriver->getScalar($stmt); } public function execute(DbDriverInterface $dbDriver, ?array $array = null): void { $stmt = $dbDriver->prepareStatement($this->sql, $array, $this->cachedStatement); $dbDriver->executeCursor($stmt); } protected function cacheResult($key, GenericIterator $iterator, ?CacheInterface $cache, $ttl): GenericIterator { if (!empty($cache)) { $cachedItem = $iterator->toArray(); $cache->set($key, $cachedItem, $ttl); return (new ArrayDataset($cachedItem))->getIterator(); } return $iterator; } /** * @return mixed * @throws InvalidArgumentException */ protected function mutexIsLocked(string $cacheKey): mixed { if (empty($this->cache)) { return false; } return $this->cache->get($cacheKey . ".lock", false); } /** * @throws InvalidArgumentException */ protected function mutexLock(string $cacheKey): void { if (empty($this->cache)) { return; } $this->cache->set($cacheKey . ".lock", time(), DateInterval::createFromDateString('5 min')); } /** * @throws InvalidArgumentException */ protected function mutexRelease(string $cacheKey): void { if (empty($this->cache)) { return; } $this->cache->delete($cacheKey . ".lock"); } }__halt_compiler();----SIGNATURE:----iZ/oOYUhd6B3PgqDSzwYWA21JLdjAcRBU00hVrwk28EKyljPCDlIJNRtaSbQrF62mhniZsJrDQCW/T2RJSe4wrm/dX32w0763p0ZD5YFjAcoH3V+KmMjdTmlpRt8TdXHf3LRWOr+UDbcD0lqZjPEe7gkJ4TVHEyItyyEbFz0VbuMjgd7MoCbzSLsO+1DKA3LdB/K0Yji9l95yysANXwlRa3e3mbd35ZzaJy3GM2WjMCFSF2jl+HWNIka0mEYm8Vww3BffdUmiQeSOcCFk+gbXEYyLM8491fd5Vt9I12KkxN00U1AVPxjtraZnb00prI6javmuf/G1qhsodg161hIHYqwSzueejuoUCrcO3KRbcKKb2btIh7h8knp8t7g4pEezG9/vpiLoMGfXyvvMD+ApgGl18xX77zWMiEBL/hV1XcBoxaWIiwm8tG7QHN5+qElqWuQ0nk+MN4EoPR1YX8qqP+gPiRgNSHp96cwUQDKNWkDBKoKpHxwR5RYqV4t2ndLmNvYnmV6dJqFnBGE89cyLtl/zWYWm4mtvafku8yndu+1mXwTSRMH+N8YdCODfwiGwLiurHQV/91cDPaFLnsTarChj7ITRQEErDayjPnn49vHxhailSXdzjEO+x08rJBW1O4OsJMSsWGEAlXJOf3nNks+taAgk/+LtJ0dtjA5tdg=----ATTACHMENT:----NDc2NTE4NTkyMjY3MjQzOCA0NDg0NDE3MjE2NjM0MDQgNDc2OTY0MDMyODMxMzcxMQ==