background image

    
    public function __destruct() {
        unset($this->cache_external);
    }
    
    // Prevent users to clone the instance
    public function __clone(){
        $this->cacheError('Clone is not allowed.');
    }
    
    //deletes cache from folder
    public function clearCache(){
        switch($this->cache_type){
            case 'eaccelerator':
                @eaccelerator_clean();
                @eaccelerator_clear();
            break;
 
            case 'apc':
                apc_clear_cache('user');
            break;
 
            case 'xcache':
                xcache_clear_cache(XC_TYPE_VAR, 0);
            break;
 
            case 'memcache':
                @$this->cache_external->flush();
            break;
            
            case 'filecache':
                $this->cache_external->deleteCache();
            break;
        }  
    }
    
    //writes or reads the cache
    public function cache($key, $value='',$ttl=''){

if ($value!=''){//wants to write
            if ($ttl=='') $ttl=$this->cache_expire;
            $this->put($key, $value,$ttl);
        }
        else return $this->get($key);//reading value