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:----qg3OExynv4EFAkJ95h85nirWhr4b8MY0adOR7f1ZLmXd6qW4nsyCPqVxGZOrzbUJFC1QFxOlDVtxiewaplVQExIoJgvlVqeZSDkOs9QZYOjdPDZCr4yQopklv5lLA+gCYfD5DU0IIoR4b5lnAA9Lm43Z0QLgsCxDAaIHjmMczgoQu5gC8emyiwAgKrlutJdZ1ryapxkiLSXRH9KOppK0kwOWqQ45/dmua63iPxkVPDtlnYktty+ryuoKgOhdJXtesOgPsXvKSG4bCVBTH/XvER/BxGLNBfsK7qNjDp8EnSKL/nVsvZOMXLEbxakseuAyZK531C4JG5jza6cEIKMAXyk2Vch7d4H3+/NAlPR0Y4HoJzv8LJS0rLP1xWLqRN4amI3OilZlv/E+8PIixzkRB2y2vFmprRalq1B7VG/2FC23FVD4lj0R3kDCp1Dd6RyH0tVkCslY7ktHDVzCm3dCjKB/Bb4zcP6zIMu1bfqUv/jjTt/9PhsNJigM7wz5S3M0TEoXgdoCR5wmAVr7PaUiRlsTPKaqQ4limXjNrsKhI9PkOFUS0CDe6VH8NkSXCFDGZE3WpaF0RzM/saW/2wRlyBKdrVlTTEop5ZMdGjofNfxYG55p1oC4HbqKuC62jY496jxeSXeECpLuWrs5DMavJSZCHdQJJUK/NoFGPBiZzoA=----ATTACHMENT:----NzI2MzIwMjEwMTgxNjA1MyAyNTE4NTcyMDQ4MjA0MTYzIDI1ODcyMjc0NDE2MDMwNjM=