Commit 2161b02d authored by Alex Ne's avatar Alex Ne

Проверка Мемкеш

parent bde3f2bd
<?php <?php
namespace X\Cache; namespace X\Cache;
class Memcache extends \memcache class Memcache
{ {
/**
* @var mixed
*/
protected $compression = false; protected $compression = false;
/**
* @var mixed
*/
protected $prefix; protected $prefix;
/**
* @var mixed
*/
protected $mcache = false; protected $mcache = false;
function __construct( $prefix, $host = "localhost", $port = 11211, $compression = false ) /**
* @param $prefix
* @param $host
* @param $port
* @param $compression
*/
public function __construct($prefix, $host = "localhost", $port = 11211, $compression = false)
{ {
$this->prefix = $prefix; if (class_exists("\memcache"))
$this->compression = $compression; {
$this->connect($host,$port); $this->prefix = $prefix;
$this->compression = $compression;
$this->mcache = new \memcache();
$this->mcache->connect($host, $port)
|| $this->mcache = false;
}
} }
public function set( $key, $value, $expire = 240 ) /**
* @param $key
* @param $value
* @param $expire
*/
public function set($key, $value, $expire = 240)
{ {
if ( ! $this->mcache)
{
return $this->mcache;
}
$key = $this->prefix . $key; $key = $this->prefix . $key;
return parent::set( md5($key), $value, $this->compression, $expire); return $this->mcache->set(md5($key), $value, $this->compression, $expire);
} }
/**
* @param $key
*/
public function get($key) public function get($key)
{ {
if ( ! $this->mcache)
{
return $this->mcache;
}
$key = $this->prefix . $key; $key = $this->prefix . $key;
return parent::get( md5($key), $this->compression); return $this->mcache->get(md5($key), $this->compression);
} }
} }
?> ?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment