Location: PHPKode > projects > Blackwolf CMF > projectBlackWolf/lib/Cache/Controller/Memcache.class.php
<?php
/* Please see the README and LICENSE files. */

/**
 * Provides an API for memcache activity
 */
class Cache_Controller_Memcache extends Cache_Controller {
    /**
     * The location and port of memcache servers to use
     * @var List<String,int>
     */
    protected static $memcache_servers = array(
        "localhost",11211
    );
    
    /**
     * A connection to the servers
     * @var type
     */
    protected $connection;
   
    /**
     * Make a new object
     */
    public function __construct(){
        $this->connect();
    }
    /**
     * Destroy connections and object
     */
    public function __destruct(){
        if(!$this->connection){return;}
        $this->connection->close();
    }
    
    
    /**
     * @see Cache_Controller
     */
    public function set($key,$val,$expire=0,$overwrite=false){
        if(!$this->connection){return;}
        $this->connection->set($key,$val,MEMCACHE_COMPRESSED,$expire);
    }  
    /**
     * @see Cache_Controller
     */
    public function get($key){
        if(!$this->connection){return;}
        return $this->connection->get($key,MEMCACHE_COMPRESSED);
    }
    /**
     * @see Cache_Controller
     */
    public function has($name) {
        # TODO
        return false;
    }
    /**
     * @see Cache_Controller
     */
    public function clear($key=NULL) {
        if(!$this->connection){return;}
        $this->connection->flush();
    }
    
    /**
     * Connect to the available servers
     */
    public function connect(){
        $this->connection = new Memcache;
        foreach(self::$memcache_servers as $key=>$val){
            $this->connection->addserver($key, $val,true,1,1,15,true,array($this,"server_failure"));
        }
    }
    
    /**
     * Callback function for failed connections
     * @param String $host The failed hostname
     * @param String $port The failed port
     */
    public static function server_failure($host,$port){
        trigger_error("Failed to connect to memcache server $host:$port",E_USER_NOTICE);
    }
    

    
}

?>
Return current item: Blackwolf CMF