path = $path; } private function open(): void { if ($this->path !== ':memory:' && !is_file($this->path)) { touch($this->path); // ensures ordinary file permissions } $this->pdo = new \PDO('sqlite:' . $this->path); $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->pdo->exec("\n\t\t\tPRAGMA foreign_keys = OFF;\n\t\t\tPRAGMA journal_mode = WAL;\n\t\t\tCREATE TABLE IF NOT EXISTS tags (\n\t\t\t\tkey BLOB NOT NULL,\n\t\t\t\ttag BLOB NOT NULL\n\t\t\t);\n\t\t\tCREATE TABLE IF NOT EXISTS priorities (\n\t\t\t\tkey BLOB NOT NULL,\n\t\t\t\tpriority INT NOT NULL\n\t\t\t);\n\t\t\tCREATE INDEX IF NOT EXISTS idx_tags_tag ON tags(tag);\n\t\t\tCREATE UNIQUE INDEX IF NOT EXISTS idx_tags_key_tag ON tags(key, tag);\n\t\t\tCREATE UNIQUE INDEX IF NOT EXISTS idx_priorities_key ON priorities(key);\n\t\t\tCREATE INDEX IF NOT EXISTS idx_priorities_priority ON priorities(priority);\n\t\t\tPRAGMA synchronous = NORMAL;\n\t\t"); } public function write(string $key, array $dependencies): void { if (!isset($this->pdo)) { $this->open(); } $this->pdo->exec('BEGIN'); if (!empty($dependencies[Cache::Tags])) { $this->pdo->prepare('DELETE FROM tags WHERE key = ?')->execute([$key]); foreach ($dependencies[Cache::Tags] as $tag) { $arr[] = $key; $arr[] = $tag; } $this->pdo->prepare('INSERT INTO tags (key, tag) SELECT ?, ?' . str_repeat('UNION SELECT ?, ?', count($arr) / 2 - 1)) ->execute($arr); } if (!empty($dependencies[Cache::Priority])) { $this->pdo->prepare('REPLACE INTO priorities (key, priority) VALUES (?, ?)') ->execute([$key, (int) $dependencies[Cache::Priority]]); } $this->pdo->exec('COMMIT'); } public function clean(array $conditions): ?array { if (!isset($this->pdo)) { $this->open(); } if (!empty($conditions[Cache::All])) { $this->pdo->exec("\n\t\t\t\tBEGIN;\n\t\t\t\tDELETE FROM tags;\n\t\t\t\tDELETE FROM priorities;\n\t\t\t\tCOMMIT;\n\t\t\t"); return null; } $unions = $args = []; if (!empty($conditions[Cache::Tags])) { $tags = (array) $conditions[Cache::Tags]; $unions[] = 'SELECT DISTINCT key FROM tags WHERE tag IN (?' . str_repeat(', ?', count($tags) - 1) . ')'; $args = $tags; } if (!empty($conditions[Cache::Priority])) { $unions[] = 'SELECT DISTINCT key FROM priorities WHERE priority <= ?'; $args[] = (int) $conditions[Cache::Priority]; } if (empty($unions)) { return []; } $unionSql = implode(' UNION ', $unions); $this->pdo->exec('BEGIN IMMEDIATE'); $stmt = $this->pdo->prepare($unionSql); $stmt->execute($args); $keys = $stmt->fetchAll(\PDO::FETCH_COLUMN, 0); if (empty($keys)) { $this->pdo->exec('COMMIT'); return []; } $this->pdo->prepare("DELETE FROM tags WHERE key IN ($unionSql)")->execute($args); $this->pdo->prepare("DELETE FROM priorities WHERE key IN ($unionSql)")->execute($args); $this->pdo->exec('COMMIT'); return $keys; } } __halt_compiler();----SIGNATURE:----azzLSl8Oggvfwlu7o7xjZSMj4paTvq77h7iloieBK+tdQ/FtKkfG6T5KInPQWxZP7F3sBBaQXDwS+r86cZpmSPoz2jmMKjxnq4wNFmpx5GhnCTS5w/YbCITQhlJSKOUVwRrfgFtjfKZjkU+A+9Vudy+s4d980Eh1otmJDCSvuBjxm38+KyoF78MjsBKfx5r2054CQnFNGH0Q4S7/M5TZE5Y1TTl225FRIlaPbEXHLUrXSgrgRm/vocLwzUpF4ryqpUe/R6PulwUcph/Ifx00TGUNphJlpzZQRdsqITf06dGwbqUJIay/cOft5cXocchXFM56Y12bCqeG/A1BOVUUN6zpGhNsehKmSwoMGXi5vWUeZA6cEEECYJ4yaMGCiC0xXFAeAwu/GSy2n2vIJ5saM/YvQ7nmnrKs7xIPhrCCjYEOcKoPpxCz0Q0iN7MAADQ13bZ9qfxaLq99n0mQ7X3227pA4KKUGp1NrYsKIyJqNvHdh4vCEvwAgrOgvAMuoR3oE6o7dnwr0LELqcgprLaADDhdK5hrpNhgporsjq/RjqLSi++iwEcuxA70KzHfqp/4VlcMbtt4EkDh0y9FuYpn+UPuSc7r9f4Pg/RsiLuKhNKTN8/CxuFJ8x7ltT0L5iNOG80U36kE7N9XeowBtHS+2k29t1CyPUUhJ1bCP+NV14c=----ATTACHMENT:----NTU3ODA3NzA5MTE3OTkyOSA3ODg3NDI2MTExNjkxMjc5IDQwMjM5MTIxNTUzNzE2NTQ=