Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
"spiral/attributes": "^2.8|^3.0",
"tochka-developers/jsonrpc-annotations": "^1.1",
"psr/simple-cache": "^1.0|^2.0"
"psr/simple-cache": "^1.0|^2.0|^3.0"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
Expand Down
28 changes: 15 additions & 13 deletions src/Helpers/ArrayFileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,38 @@ protected function loadAllData(): void
}
}

protected function saveAllData(): void
protected function saveAllData(): bool
{
if (!is_dir($this->cachePath) && !mkdir($this->cachePath) && !is_dir($this->cachePath)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $this->cachePath));
}

file_put_contents($this->getCacheFilePath(), '<?php return ' . var_export($this->data, true) . ';' . PHP_EOL);
return (bool) file_put_contents($this->getCacheFilePath(), '<?php return ' . var_export($this->data, true) . ';' . PHP_EOL);
}

public function get($key, $default = null)
public function get($key, $default = null): mixed
{
$this->loadAllData();

return array_key_exists($key, $this->data) ? $this->data[$key] : $default;
}

public function set($key, $value, $ttl = null)
public function set($key, $value, $ttl = null): bool
{
$this->loadAllData();

$this->data[$key] = $value;

$this->saveAllData();
return $this->saveAllData();
}

public function delete($key)
public function delete($key): bool
{
$this->loadAllData();

unset($this->data[$key]);

$this->saveAllData();
return $this->saveAllData();
}

public function getMultiple($keys, $default = null): array
Expand All @@ -81,34 +81,36 @@ public function getMultiple($keys, $default = null): array
return $result;
}

public function setMultiple($values, $ttl = null)
public function setMultiple($values, $ttl = null): bool
{
$this->loadAllData();

$this->data = array_merge($this->data, $values);
$this->data = array_merge($this->data, (array) $values);

$this->saveAllData();
return $this->saveAllData();
}

public function deleteMultiple($keys)
public function deleteMultiple($keys): bool
{
$this->loadAllData();

foreach ($keys as $key) {
unset($this->data[$key]);
}

$this->saveAllData();
return $this->saveAllData();
}

public function clear(): void
public function clear(): bool
{
$this->data = [];

$filePath = $this->getCacheFilePath();
if (file_exists($filePath)) {
unlink($filePath);
}

return true;
}

public function has($key): bool
Expand Down