function test_init_with_wrong_server_using_AkCache_init() { $cache=new AkCache(); $res = $cache->init(array('servers'=>array('test:121')),3); $this->assertFalse($res); $this->assertError('Could not connect to MemCache daemon'); $this->assertFalse($cache->cache_enabled); }
/** * Instantiates and configures the AkCache store. * * If $options == NULL the configuration will be taken from the constants: * * AK_CACHE_HANDLER and AK_CACHE_OPTIONS * * if $options is of type string/int the $options parameter will be considered * as the AK_CACHE_HANDLER_* Type (AK_CACHE_HANDLER_PEAR,AK_CACHE_HANDLER_ADODB,AK_CACHE_HANDLER_MEMCACHE) * * if $options is an array of format: * * array('file'=>array('cacheDir'=>'/tmp')) * * or * * array(AK_CACHE_HANDLER_PEAR=>array('cacheDir'=>'/tmp')) * * the first key will be used as the AK_CACHE_HANDLER_* Type * and the array as the config options * * Default behaviour is calling the method with the $options == null parameter: * * AkCache::lookupStore() * * Calling it with: * * AkCache::lookupStore(true) * * will return the configured $cache_store * * @param mixed $options * @return mixed false if no cache could be configured or AkCache instance */ function &lookupStore($options = null) { static $cache_store; $false = false; if ($options === true && !empty($cache_store)) { return $cache_store; } else { if (is_array($options) && isset($options['enabled']) && $options['enabled'] == true && isset($options['handler']) && isset($options['handler']['type'])) { $type = $options['handler']['type']; $options = isset($options['handler']['options']) ? $options['handler']['options'] : array(); } else { if (is_string($options) || is_int($options)) { $type = $options; $options = array(); } else { return $false; } } } $cache_store = new AkCache(); $cache_store->init($options, $type); if ($cache_store->cache_enabled) { return $cache_store; } return $false; }