Example #1
0
 public static function init()
 {
     if (!self::$collection) {
         self::$client = new \MongoClient();
         self::$db = self::$client->{self::dbName};
         self::$collection = self::$db->{self::collectionName};
     }
 }
 function loaddata($keystring)
 {
     $configvalue = $this->CharName_ . '_CharacterSheet';
     $CachedTime = ApiCache::get($configvalue);
     $UseCaching = config::get('API_UseCache');
     $url = API_SERVER . "/char/CharacterSheet.xml.aspx" . $keystring;
     $path = '/char/CharacterSheet.xml.aspx';
     // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round.
     if ($CachedTime == "") {
         $CachedTime = "2005-01-01 00:00:00";
         // fake date to ensure that it runs first time.
     }
     if (is_file(KB_CACHEDIR . '/api/' . $configvalue . '.xml')) {
         $cacheexists = true;
     } else {
         $cacheexists = false;
     }
     // if API_UseCache = 1 (off) then don't use cache
     if (strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0 || $UseCaching == 1 || !$cacheexists) {
         $http = new http_request($url);
         $http->set_useragent("PHPApi");
         foreach ($keystring as $key => $val) {
             $http->set_postform($key, $val);
         }
         $contents = $http->get_content();
         $start = strpos($contents, "?>");
         if ($start !== FALSE) {
             $contents = substr($contents, $start + strlen("\r\n\r\n"));
         }
         // Save the file if we're caching (0 = true in Thunks world)
         if ($UseCaching == 0) {
             $file = fopen(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 'w+');
             fwrite($file, $contents);
             fclose($file);
             @chmod(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 0666);
         }
     } else {
         // re-use cached XML
         if ($fp = @fopen(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 'r')) {
             $contents = fread($fp, filesize(KB_CACHEDIR . '/api/' . $configvalue . '.xml'));
             fclose($fp);
         } else {
             return "<i>error loading cached file " . $configvalue . ".xml</i><br><br>";
         }
     }
     return $contents;
 }
Example #3
0
function delCache($string,$dir='') {
	  $ar = explode(':',$string);
	  if(count($ar)>1){
		$module = $ar[0];
		$name = $ar[1];
	  }else{
		$module = MODULE_NAME;
		$name = $ar[0];  
	  }
	  //集群部署
	  if(C('WEB_DEPLOY_TYPE')==1 && C('DATA_CACHE_TYPE')=='File'){
		GLOBAL $config;
		if(!$config){
			//载入配置
			require_once(C('INTERFACE_PATH')."Cache/config.php");
			require_once(C('INTERFACE_PATH')."Cache/ApiCache.class.php");
		}
		$cache = new ApiCache($config);
		$para['c'] = 'Local';
		$para['a'] = 'Del';
		$para['name'] = $name;
		$data['name'] = $name;
		$data['dir'] = $data['dir'] ? $module.'/'.$data['dir'] : $module;
		$data['module'] = $module;
		$result = json_decode($cache->rm($para,$data),true);
		if($result['error_code']==0){
		  return true;
		}else{
		  return false;
		}
	  }else{
		  $dir = $data['dir'] ? $data['dir'] : $module;
		  $expire = $data['expire'];
		  $options['temp'] = C('DATA_CACHE_PATH').$dir;
		  $options['filename'] = $name;
		  $cache = new Cache();
		  $cache = $cache->connect(C('DATA_CACHE_TYPE'),$options);
		  $cache->getInstance();
		  $data = $cache->rm($name);
		  return $data;
	  }
}
Example #4
0
 public static function getCheck()
 {
     return array('rates' => ApiCache::getCheck(Yii::app()->params['cache']['keys']['rates']), 'departments' => ApiCache::getCheck(Yii::app()->params['cache']['keys']['departments']), 'coordinates' => ApiCache::getCheck(Yii::app()->params['cache']['keys']['coordinates']));
 }