mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-07-16 00:44:44 +02:00
refacor: improve cache interface (#3492)
* fix: proper typehint on setScope * refactor: type hint setKey() * typehint
This commit is contained in:
parent
f8801d8cb3
commit
caac7f572c
13 changed files with 56 additions and 220 deletions
|
@ -2,8 +2,8 @@
|
|||
|
||||
class MemcachedCache implements CacheInterface
|
||||
{
|
||||
private $scope;
|
||||
private $key;
|
||||
private string $scope;
|
||||
private string $key;
|
||||
private $conn;
|
||||
private $expiration = 0;
|
||||
private $time = null;
|
||||
|
@ -58,11 +58,11 @@ class MemcachedCache implements CacheInterface
|
|||
return $result['data'];
|
||||
}
|
||||
|
||||
public function saveData($datas)
|
||||
public function saveData($data): void
|
||||
{
|
||||
$time = time();
|
||||
$object_to_save = [
|
||||
'data' => $datas,
|
||||
'data' => $data,
|
||||
'time' => $time,
|
||||
];
|
||||
$result = $this->conn->set($this->getCacheKey(), $object_to_save, $this->expiration);
|
||||
|
@ -72,8 +72,6 @@ class MemcachedCache implements CacheInterface
|
|||
}
|
||||
|
||||
$this->time = $time;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTime(): ?int
|
||||
|
@ -84,32 +82,21 @@ class MemcachedCache implements CacheInterface
|
|||
return $this->time;
|
||||
}
|
||||
|
||||
public function purgeCache($duration)
|
||||
public function purgeCache(int $seconds): void
|
||||
{
|
||||
// Note: does not purges cache right now
|
||||
// Just sets cache expiration and leave cache purging for memcached itself
|
||||
$this->expiration = $duration;
|
||||
$this->expiration = $seconds;
|
||||
}
|
||||
|
||||
public function setScope($scope)
|
||||
public function setScope(string $scope): void
|
||||
{
|
||||
$this->scope = $scope;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setKey($key)
|
||||
public function setKey(array $key): void
|
||||
{
|
||||
if (!empty($key) && is_array($key)) {
|
||||
$key = array_map('strtolower', $key);
|
||||
}
|
||||
$key = json_encode($key);
|
||||
|
||||
if (!is_string($key)) {
|
||||
throw new \Exception('The given key is invalid!');
|
||||
}
|
||||
|
||||
$this->key = $key;
|
||||
return $this;
|
||||
$this->key = json_encode($key);
|
||||
}
|
||||
|
||||
private function getCacheKey()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue