funchat/inc/cache.class.php

106 lines
2.6 KiB
PHP
Raw Normal View History

2025-06-02 10:01:12 +02:00
<?php
2025-06-23 20:45:15 +02:00
$module["cache"]["name"]="Cache Class";
$module["cache"]["ver"]="0.9.10";
2025-06-02 10:01:12 +02:00
/**
2025-06-23 20:45:15 +02:00
* Project: BeCast WebEngine - simple site engine
2025-06-03 23:02:49 +02:00
* File: /inc/cache.class.php
2025-06-02 10:01:12 +02:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
2025-06-23 20:45:15 +02:00
* @link http://www.becast.at
* @copyright 2009-2025 becast.at
2025-06-02 10:01:12 +02:00
* @author Bernhard Jaud <bernhard at becast dot at>
2025-06-23 20:45:15 +02:00
* @package BcWe core
2025-06-02 10:01:12 +02:00
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
2025-06-23 20:45:15 +02:00
*/
2025-06-02 10:01:12 +02:00
/*
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);
*/
2025-06-23 20:45:15 +02:00
2025-06-02 10:01:12 +02:00
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);
2025-06-02 22:38:25 +02:00
$con = $this->connect($this->server,$this->port);
2025-06-02 10:01:12 +02:00
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();
}
2025-06-23 20:45:15 +02:00
function set($key,$var,$exp=null): void
{
if($exp==null){
$expiration = $this->exp;
}else{
$expiration = $exp;
2025-06-02 10:01:12 +02:00
}
$this->obj->set($this->prefix.$key,$var,$expiration);
2025-06-23 20:45:15 +02:00
}
2025-06-02 10:01:12 +02:00
function get($key){
return $this->obj->get($this->prefix.$key);
}
}
?>