Skip to content

Instantly share code, notes, and snippets.

@mustafaileri
Created June 18, 2010 20:48
Show Gist options
  • Save mustafaileri/444210 to your computer and use it in GitHub Desktop.
Save mustafaileri/444210 to your computer and use it in GitHub Desktop.
<?php
class MCache
{
private $memcache;
private $memcachehost;
private $memcacheport;
private $flag = FALSE;
/**
*
*/
function __construct()
{
global $bo_config;
$this->memcachehost = $bo_config["memcache"]["host"];
$this->memcacheport = $bo_config["memcache"]["port"];
if (!$this->memcache){
$this->memcache = new Memcache();
}
$conn = $this->memcache->pconnect($this->memcachehost, $this->memcacheport);
if (!$conn){
die ("MemCache Error");
}
}
/**
* Set Value on MemCache as MemCachekey, MemcacheVal, ExpiredTime(default1800 seconds)
* @param $key :
* @param $val
* @param $expire
*/
function _set($key, $val, $expire = 86400)
{
$flag = $this->flag;
$this->memcache->set($key, $val, $flag, $expire);
}
/**
* Get Value From Memcache
* @param $key
*/
function _get($key)
{
global $bo_config;
if ($bo_config["debugMode"] == 1) {
return false;
}
$value = $this->memcache->get($key);
return $value;
}
/**
*
* @param string $key
* Unset key on Memcache
*/
function _unset($key)
{
$flag = $this->flag;
$this->memcache->set($key, NULL, $flag, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment