diff --git a/src/Caching/Storages/SQLiteStorage.php b/src/Caching/Storages/SQLiteStorage.php index 55a558f1..eb409fce 100644 --- a/src/Caching/Storages/SQLiteStorage.php +++ b/src/Caching/Storages/SQLiteStorage.php @@ -60,6 +60,7 @@ public function __construct($path) */ public function read(string $key) { + $key = self::sanitize($key); $stmt = $this->pdo->prepare('SELECT data, slide FROM cache WHERE key=? AND (expire IS NULL OR expire >= ?)'); $stmt->execute([$key, time()]); if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { @@ -77,6 +78,7 @@ public function read(string $key) */ public function bulkRead(array $keys): array { + $keys = array_map([self::class, 'sanitize'], $keys); $stmt = $this->pdo->prepare('SELECT key, data, slide FROM cache WHERE key IN (?' . str_repeat(',?', count($keys) - 1) . ') AND (expire IS NULL OR expire >= ?)'); $stmt->execute(array_merge($keys, [time()])); $result = []; @@ -108,6 +110,7 @@ public function lock(string $key): void */ public function write(string $key, $data, array $dependencies): void { + $key = self::sanitize($key); $expire = isset($dependencies[Cache::EXPIRATION]) ? $dependencies[Cache::EXPIRATION] + time() : null; $slide = isset($dependencies[Cache::SLIDING]) ? $dependencies[Cache::EXPIRATION] : null; @@ -133,7 +136,7 @@ public function write(string $key, $data, array $dependencies): void public function remove(string $key): void { $this->pdo->prepare('DELETE FROM cache WHERE key=?') - ->execute([$key]); + ->execute([self::sanitize($key)]); } @@ -159,10 +162,16 @@ public function clean(array $conditions): void if (!empty($conditions[Cache::NAMESPACES])) { foreach ($conditions[Cache::NAMESPACES] as $namespace) { $sql .= ' OR key LIKE ?'; - $args[] = $namespace . Cache::NAMESPACE_SEPARATOR . '%'; + $args[] = self::sanitize($namespace . Cache::NAMESPACE_SEPARATOR . '%'); } } $this->pdo->prepare($sql)->execute($args); } + + + private function sanitize($key) + { + return str_replace(Cache::NAMESPACE_SEPARATOR, "\x01", $key); + } }