diff --git a/plugins/views_plugin_cache.inc b/plugins/views_plugin_cache.inc
index ceef865..22029a6 100644
--- a/plugins/views_plugin_cache.inc
+++ b/plugins/views_plugin_cache.inc
@@ -52,7 +52,7 @@ class views_plugin_cache extends views_plugin {
    *   The cache type, either 'query', 'result' or 'output'.
    */
    function cache_expire($type) { }
-   
+
    /**
     * Determine expiration time in the cache table of the cache type
     * or CACHE_PERMANENT if item shouldn't be removed automatically from cache.
@@ -172,7 +172,7 @@ class views_plugin_cache extends views_plugin {
    */
   function cache_start() {
     $this->storage['head'] = drupal_add_html_head();
-    $this->storage['css'] = drupal_add_css();  
+    $this->storage['css'] = drupal_add_css();
     $this->storage['js'] = drupal_add_js();
   }
 
@@ -251,13 +251,18 @@ class views_plugin_cache extends views_plugin {
     global $user;
 
     if (!isset($this->_results_key)) {
-      
+
       $build_info = $this->view->build_info;
-      
+      $query_plugin = $this->view->display_handler->get_plugin('query');
+
       foreach (array('query', 'count_query') as $index) {
-        $query = clone $build_info[$index];
-        $query->preExecute();
-        $build_info[$index] = (string)$query;
+        // If the default query back-end is used generate SQL query strings from
+        // the query objects.
+        if ($build_info[$index] instanceof SelectQueryInterface) {
+          $query = clone $build_info[$index];
+          $query->preExecute();
+          $build_info[$index] = (string)$query;
+        }
       }
       $key_data = array(
         'build_info' => $build_info,
