diff --git a/src/Cache.php b/src/Cache.php index f9202e0..9578dc4 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -64,11 +64,12 @@ private function isAllowPackingObject(object $objectForPacking): bool public function get($key, $default = null) { $data = ''; + $key = str_replace('//', '/', "/$key"); $isSuccess = (bool)$this->cacheEngine->read( $data, $this->baseDir, $this->initDir, - "/$key", + $key, $this->defaultTtl ); @@ -98,6 +99,7 @@ public function get($key, $default = null) */ public function set($key, $value, $ttl = null): bool { + $key = str_replace('//', '/', "/$key"); if (is_object($value)) { if (!$this->isAllowPackingObject($value)) { throw new Exception('this is not allowed for packing'); @@ -109,7 +111,7 @@ public function set($key, $value, $ttl = null): bool $value = json_encode($value); } - $this->cacheEngine->write($value, $this->baseDir, $this->initDir, "/$key", $ttl ?? $this->defaultTtl); + $this->cacheEngine->write($value, $this->baseDir, $this->initDir, $key, $ttl ?? $this->defaultTtl); return true; } @@ -119,6 +121,7 @@ public function set($key, $value, $ttl = null): bool */ public function delete($key): bool { + $key = str_replace('//', '/', "/$key"); $this->cacheEngine->clean($this->baseDir, $this->initDir, $key); return true; } @@ -184,12 +187,13 @@ public function deleteMultiple($keys): bool */ public function has($key): bool { + $key = str_replace('//', '/', "/$key"); $data = ''; return (bool)$this->cacheEngine->read( $data, $this->baseDir, $this->initDir, - "/$key", + $key, $this->defaultTtl ); }