}
		else if($debug)
		{
			print "not found<br>\n";
		}
	}elseif($debug){
		print "Matched cache exclusion rule: '".$rule_match['pattern']."' with: '".$rule_match['number']."'<br>\nSkipping cache 
lookup.<br>\n";
	}
}

if($usage_mode == 'post processing')
{
	// Compatbility for pre 2.2.4
	if(function_exists("match_pattern_all")){ 
		$rule_match = match_pattern_all(isset($run_param['CID_Exclusion_Rules'])?$run_param['CID_Exclusion_Rules']:'' , $thenumber);
	}else{
		$rule_match = array('status'=>false,'number'=>false);
	}
	if((!$rule_match['status']) || (!$rule_match['number'])){
		if(!$cache_found && ($first_caller_id != ''))
		{
			$sql = "REPLACE INTO superfectacache (number,callerid,dateentered)
							VALUES($thenumber,'$first_caller_id',NOW())";
			$db->query($sql);
			if($debug)
			{
				print "Caller ID data added to cache.<br>\n<br>\n";
			}
		}
	}elseif($debug){

		// Determine if this is the correct DID, if this scheme is limited to a DID.

		$rule_match = match_pattern_all( (isset($param[$this_scheme]['DID'])) ? $param[$this_scheme]['DID'] : '', $DID );
		if($rule_match['number']){
			if($debug){print "Matched DID Rule: '".$rule_match['pattern']."' with '".$rule_match['number']."'<br>\n";}
		}elseif($rule_match['status']){
			if($debug){print "No matching DID rules.<br>\n";}
			$run_this_scheme = false;
		}


		// Determine if the CID matches any patterns defined for this scheme

		$rule_match = match_pattern_all((isset($param[$this_scheme]['CID_rules']))?$param[$this_scheme]['CID_rules']:'', $thenumber );
		if($rule_match['number'] && $run_this_scheme){
			if($debug){print "Matched CID Rule: '".$rule_match['pattern']."' with '".$rule_match['number']."'<br>\n";}
			$thenumber = $rule_match['number'];
		}elseif($rule_match['status'] && $run_this_scheme){
			if($debug){print "No matching CID rules.<br>\n";}
			$run_this_scheme = false;
		}

		// Run the scheme
		
		if($run_this_scheme)
		{
			$curl_timeout = $param[$this_scheme]['Curl_Timeout'];

			//if a prefix lookup is enabled, look it up, and truncate the result to 10 characters