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:----QRQQmvgnT11LGgHHBHNzuh5eXhbu/UevYgluL8LXhwyhRiTphAHADiHVGXrAA9Lqw//uQWoY85e2fBxRu1/InP9Azni6lAAHgV1CMoQ5TzDEMSO0OqiVJdv9+WlVyUqGXC1nmW+pIs5b+ijXDK0eUyI7Z+SaDPNrypsGN6yX+/06GDMMhAJKaFa9g4dLkPBHkgspzpbnHeFgOLr0deWJYuKKZVe4u78ZDGbxB3PZc47fgRn+PPZc33bCSpZqrFOZHSDW868Y/quQiHH/oDLXPd4k4a+Hu5b7KMfxuaMbdYF+hWUX9+PQbGcozPoX6n5c4nmtQG9d3HAjkojno4QHOEf4p5TU/S0LmflGAKnRLl5ckBm5InM9AcvwetaSd92XAjpPhAOal6XqvPfk5aKhwh2p7uo8iZC3nOeRU+LaqEf5BLcalcP5YEWylrbYRcdgoYMok8hkIkKeIWWWcN3/sf/CCWbk8Ry9SmIx3KjRAlBOG5iGayj7C1UJQhrpa1sQ9cqugw79T/vMZhMbKUofagBQV6K7RW/MdX0s8AAnIfEIF7LyWPvHQfZmzrlqzVM6pUewMPGtkPJ7aUz3XXd4QBY3uGzW9H39rs85AjK1lLjfkFa1TfYKRmEIW6FP+JTCCsisSYL4hMrzmj5sCbi0Q6voMbursThAtfYssDP/Hmk=----ATTACHMENT:----MjM2MzAwMTczMDU0NDgxNyA4MTMyMjAwNzc4NDQzNjU2IDk4MzkxMTQ4MjAzNDM1MTU=