<?php 
$myMemCacheObj = new CacheMemcache();

class CacheMemcache {
    var $cacheExptime = 86400; // cache expire time(default 1 day)
    var $bEnabled = false; // Memcache enabled?
    var $objMcache = NULL;
	var $_prefix = '';
    // constructor
    function __construct() {
		$this->_prefix = "www.manilablossoms.top";
		
		//$this->_prefix = $_SERVER['HTTP_HOST'];
        if (class_exists('Memcached')) {
			
			
            $this->objMcache = new Memcached();
            $this->bEnabled = true;
            if (! $this->objMcache->addServer('localhost', 11211))  { // Instead 'localhost' here can be IP
                $this->objMcache = NULL;
                $this->bEnabled = false;
            }
        }
    }
    // get data from cache server
    function getData($sKey) {
        $vData = $this->objMcache->get($this->_prefix.$sKey);
        return false === $vData ? NULL : $vData;
    }
    // save data to cache server
    function setData($sKey, $vData, $cacheExptime="") {
		if($cacheExptime==""){
			$cacheExptime=$this->cacheExptime;
		}
		
        //Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
        //return $this->objMcache->set($this->_prefix.$sKey, $vData, MEMCACHE_COMPRESSED, $cacheExptime);
		return $this->objMcache->set($this->_prefix.$sKey, $vData, $cacheExptime);
    }
    // delete data from cache server
    function delData($sKey) {
        return $this->objMcache->delete($this->_prefix.$sKey);
    }
}
?>
