Skip to content

Commit

Permalink
fix(key): update cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
alex19pov31 committed Dec 8, 2023
1 parent e63be7e commit dcd5cea
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -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');
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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
);
}
Expand Down

0 comments on commit dcd5cea

Please sign in to comment.