XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
memcache.php
Go to the documentation of this file.
1 <?php
21 defined('XOOPS_ROOT_PATH') or die('Restricted access');
22 
55 {
62  var $memcache = null;
71  var $settings = array();
82  function init($settings = array())
83  {
84  if (!class_exists('Memcache')) {
85  return false;
86  }
87  parent::init($settings);
88  $defaults = array(
89  'servers' => array(
90  '127.0.0.1') ,
91  'compress' => false);
92  $this->settings = array_merge($defaults, $this->settings);
93 
94  if (!$this->settings['compress']) {
95  $this->settings['compress'] = MEMCACHE_COMPRESSED;
96  }
97  if (!is_array($this->settings['servers'])) {
98  $this->settings['servers'] = array(
99  $this->settings['servers']);
100  }
101  $this->memcache = null;
102  $this->memcache = new Memcache();
103  foreach ($this->settings['servers'] as $server) {
104  $parts = explode(':', $server);
105  $host = $parts[0];
106  $port = 11211;
107  if (isset($parts[1])) {
108  $port = $parts[1];
109  }
110  if ($this->memcache->addServer($host, $port)) {
111  return true;
112  }
113  }
114  return false;
115  }
125  function write($key, &$value, $duration)
126  {
127  return $this->memcache->set($key, $value, $this->settings['compress'], $duration);
128  }
136  function read($key)
137  {
138  return $this->memcache->get($key);
139  }
147  function delete($key)
148  {
149  return $this->memcache->delete($key);
150  }
157  function clear()
158  {
159  return $this->memcache->flush();
160  }
169  function connect($host, $port = 11211)
170  {
171  if ($this->memcache->getServerStatus($host, $port) === 0) {
172  if ($this->memcache->connect($host, $port)) {
173  return true;
174  }
175  return false;
176  }
177  return true;
178  }
179 }
180 
181 ?>