mirror of
https://github.com/YGGverse/cache-php.git
synced 2026-04-01 01:55:29 +00:00
change class name
This commit is contained in:
parent
38303b10a9
commit
98c789d7d4
1 changed files with 1 additions and 1 deletions
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace YGGverse\Cache;
|
||||
|
||||
class Memcached {
|
||||
|
||||
private $_memcached;
|
||||
private $_namespace;
|
||||
private $_timeout;
|
||||
|
||||
public function __construct(string $host, int $port, string $namespace, int $timeout)
|
||||
{
|
||||
$this->_memcached = new Memcached();
|
||||
$this->_memcached->addServer($host, $port);
|
||||
|
||||
$this->_namespace = $namespace;
|
||||
$this->_timeout = $timeout;
|
||||
}
|
||||
|
||||
public function get(string $key, mixed $value = null, int $timeout = null) : mixed
|
||||
{
|
||||
if (false === $result = $this->_memcached->get($this->_key($key)))
|
||||
{
|
||||
if (true === $this->set($key, $value, $timeout))
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
public function set(string $key, mixed $value, int $timeout = null)
|
||||
{
|
||||
return $this->_memcached->set($this->_key($key), $value, ($timeout ? $timeout : $this->_timeout) + time());
|
||||
}
|
||||
|
||||
public function delete(string $key) : bool
|
||||
{
|
||||
return $this->_memcached->delete($this->_key($key));
|
||||
}
|
||||
|
||||
public function flush(int $delay = 60)
|
||||
{
|
||||
return $this->_memcached->flush();
|
||||
}
|
||||
|
||||
private function _key(string $key) : string
|
||||
{
|
||||
return sprintf('%s.%s', $this->_namespace, $key);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue