--- C:/Users/David/Desktop/database - Copy.inc	Thu Aug 22 11:06:47 2013
+++ C:/Users/David/Desktop/database.inc	Thu Aug 22 11:04:38 2013
@@ -283,14 +283,60 @@
     }
 
     /**
      * Internal function: massage a query to make it compliant with SQL Server.
      */
     public function preprocessQuery($query) {
 
+		//ENABLE OR DISBALE CACHE FOR THIS QUERY, MAYBE APPLY SOME LOGIC TO PREVENT SOME QUERIES FROM BEING CACHES (TOO LONG, ETC)
+		//CURRENT TESTING SHOWS THAT WITHOUT FILTER CACHE ITEM WILL GROW TO APROX. 1MB
+		$cache_query = true; 
+		//SPECIFIC KEY FOR THIS QUERY, NULL IF NO CACHING
+		$key = $cache_query ? md5($query) : null; 
+		//QUERY CACHE STATIC FOR FAST ACCESS
+		static $query_cache;
+		//NUMBER OF NEW CACHED QUERIES DURING THIS REQUEST
+		static $query_count;
+		
+		//INITIALIZE PER-REQUEST CACHING MECHANISM
+		if($cache_query && !isset($query_cache))
+		{
+			$query_count = 0;
+		
+			if($cache = cache_get('preprocessQuery_query_cache', 'cache_sqlsrv'))
+			{
+				$query_cache = $cache->data;
+			}
+			else
+			{
+				$query_cache = array();
+			}
+			
+			$callback = function() use(&$query_cache, &$query_count)
+			{
+				$query_count = &$query_count;
+				
+				//ONLY UPDATE CACHE IF NEW QUERIES WERE ADDED
+				if($query_count > 0)
+				{
+					$query_cache = &$query_cache;
+					cache_set('preprocessQuery_query_cache', $query_cache, 'cache_sqlsrv', 0);
+				}
+			};
+			
+			//SEND TO CACHE AT END OF REQUEST TO PREVENT EXCESVIE CACHE_SET CALLS
+			register_shutdown_function($callback);
+			
+		}
+		
+		if(isset($query_cache[$key]))
+		{
+			return $query_cache[$key];
+		}
+	
         // Force quotes around some SQL Server reserved keywords.
         if (preg_match('/^SELECT/i', $query)) {
             $query = preg_replace_callback(self::RESERVED_REGEXP, array($this, 'replaceReservedCallback'), $query);
         }
 
         // Last chance to modify some SQL Server-specific syntax.
         $replacements = array(
@@ -323,14 +369,21 @@
                         );
         foreach ($replacements as $function => $replacement) {
             $query = preg_replace('/\b(?<![:.])(' . preg_quote($function) . ')\(/i', $replacement . '(', $query);
         }
 
         // Replace the ANSI concatenation operator with SQL Server poor one.
         $query = preg_replace('/\|\|/', '+', $query);
+
+		//STORE QUERY IN CACHE IF ENABLED
+		if($cache_query)
+		{
+			$query_cache[$key] = $query;
+			$query_count++;
+		}
 		
         return $query;
     }
 
     /**
      * Internal function: add range options to a query.
      *
