Commit 7be04c17 authored by Alex Ne's avatar Alex Ne

Поправка кєширования

parent 04e441ae
<?php <?php
namespace X\Cache; namespace X\Cache;
class Memcache class Memcache {
{
/**
* @var mixed
*/
protected $compression = false;
/** /**
* @var mixed * @var mixed
*/ */
...@@ -15,19 +11,16 @@ class Memcache ...@@ -15,19 +11,16 @@ class Memcache
* @var mixed * @var mixed
*/ */
protected $mcache = false; protected $mcache = false;
/** /**
* @param $prefix * @param $prefix
* @param $host * @param $host
* @param $port * @param $port
* @param $compression
*/ */
public function __construct($prefix, $host = "localhost", $port = 11211, $compression = false) public function __construct($prefix, $host = "localhost", $port = 11211) {
{ if (class_exists("\memcache")) {
if (class_exists("\memcache")) $this->prefix = $prefix;
{ $this->mcache = new \memcache();
$this->prefix = $prefix;
$this->compression = $compression;
$this->mcache = new \memcache();
$this->mcache->connect($host, $port) $this->mcache->connect($host, $port)
|| $this->mcache = false; || $this->mcache = false;
...@@ -39,29 +32,25 @@ class Memcache ...@@ -39,29 +32,25 @@ class Memcache
* @param $value * @param $value
* @param $expire * @param $expire
*/ */
public function set($key, $value, $expire = 240) public function set($key, $value, $expire = 240) {
{ if ( ! $this->mcache) {
if ( ! $this->mcache)
{
return $this->mcache; return $this->mcache;
} }
$key = $this->prefix . $key; $key = $this->prefix . $key;
return $this->mcache->set(md5($key), $value, $this->compression, $expire); return $this->mcache->set(md5($key), $value, 0, $expire);
} }
/** /**
* @param $key * @param $key
*/ */
public function get($key) public function get($key) {
{ if ( ! $this->mcache) {
if ( ! $this->mcache)
{
return $this->mcache; return $this->mcache;
} }
$key = $this->prefix . $key; $key = $this->prefix . $key;
return $this->mcache->get(md5($key), $this->compression); return $this->mcache->get(md5($key), 0);
} }
} }
?> ?>
\ 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