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:----SeAHAl7zuDdJL7HYfJwUtmktpfdr16iawvN4HluoL4IPrbRu4Aq35tcc8YnZ+4LLLYSUrEgOLVJv3dZEjT8GKmtdwy+MHDGOhhhDG7eJOn0pdYpEW9pBpeZGYPARi3hSmVCdEVXT3Pn5cchgzS3P35C4v3pfkj30Z7/UYe417sto2rZuVO3uyEigHJtb4o7u5NmhLeXdNi7MLBIRqNqdGmhGoDZnzcoQCqwT/H6N9UGbH+poTktpKRIcgmKFHcdStfGXodixb6owYINRG5DDIqKsLxXDoxjTOP0qNzXzNxwbuS9yap6m1Spnq6xqdNetPVTgovxOBo5CEYiqHwmJFMyUKE2VvGMAwX07C3VVm7keO8k3xYKYeaMbBLK7OtlBRQzTggEk/UZIYGfDBwAWw8gpbUHqNout618K2s0nEyxrRPHx+ZZnd9s1CdgooKNx81nRd9hggnUzoDluoJkOxmqedCym1KNbJvgCbd6IdpYHO1prGnsfFfEv0syX+OksrEP0PoF98t9/94xPT9RhB/EktWtA/Pi9iF/qTkdMD3KuUS2XxOUY5QwKIkK37PyeVZmSAUmCxX3vJn+AMgKJ0qcJkkJI4Zi5Ss8wyrikqn+lCA30iKJO1zOBihtWtPVHj33ChPwDhBspWgUCryVm+4N1R/V9YQ0k9+nA0K2r1w8=----ATTACHMENT:----OTg5NjI5MzIyODY5MDU5MCAxMjU1OTE2MDk3NDgwOTE0IDcyMDE3NzczNDY3OTk2MDY=