* @package BcWe core * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ */ /* Already defined by PHP. I'll leave it here for Info define("LOG_EMERG", 0); define("LOG_ALERT", 1); define("LOG_CRIT", 2); define("LOG_ERR", 3); define("LOG_WARNING", 4); define("LOG_INFO", 6); define("LOG_DEBUG", 7); */ class cache { var $server; var $prefix; var $obj; var $port; var $exp; ///////////////////////////////////////// // Module data ///////////////////////////////////////// // // __construct // // Buid logger // function __construct() { global $config, $logger; $this->server=$config['MEMCACHE_SERVER']; $this->port=$config['MEMCACHE_PORT']; $this->prefix=$config['MEMCACHE_PREFIX']; $this->exp=$config['MEMCACHE_EXPIRATION']; $this->obj = new Memcached($this->prefix); $con = $this->connect($this->server,$this->port); if(!$con){ return false; }else{ return true; } } public function connect($host , $port){ $servers = $this->obj->getServerList(); if(is_array($servers)) { foreach ($servers as $server) { if($server['host'] == $host and $server['port'] == $port){ return true; } else { return $this->obj->addServer($host , $port); } } } } function __destruct() { $this->obj->quit(); } function set($key,$var,$exp=null): void { if($exp==null){ $expiration = $this->exp; }else{ $expiration = $exp; } $this->obj->set($this->prefix.$key,$var,$expiration); } function get($key){ return $this->obj->get($this->prefix.$key); } } ?>