diff --git a/database.inc b/database.inc index e3a81ed..0d87917 100644 --- a/database.inc +++ b/database.inc @@ -86,9 +86,10 @@ class DatabaseConnection_oracle extends DatabaseConnection // Default to TCP connection on port 5432. if (empty($connection_options['port'])) $connection_options['port'] = 1521; - - if (isset($connection_options['use_cache'])) - $this->use_cache= $connection_options['use_cache']; + + // Caching settings. Check $connection_options for backwards compatibility. + $this->use_statement_cache = isset($connection_options['use_cache']) ? $connection_options['use_cache'] : variable_get('oracle_use_memcached', FALSE); + $this->use_blob_cache = variable_get('oracle_use_memcached', FALSE); $oracle_user= $connection_options['username']; @@ -381,7 +382,7 @@ class DatabaseConnection_oracle extends DatabaseConnection { $oquery= ""; - if ($this->use_cache) + if ($this->use_statement_cache) { $cached= cache_get($iquery, 'cache_oracle'); @@ -404,7 +405,7 @@ class DatabaseConnection_oracle extends DatabaseConnection $oquery= $this->prefixTables($oquery,true); $oquery= $this->escapeIfFunction($oquery); - if ($this->use_cache) + if ($this->use_statement_cache) cache_set($iquery,$oquery,'cache_oracle'); } @@ -561,9 +562,10 @@ class DatabaseConnection_oracle extends DatabaseConnection { $hash= md5($value); $handle= 0; - + $stream= DatabaseConnection_oracle::stringToStream($value); - + + // Write to database. $stmt= parent::prepare("begin identifier.write_blob(?,?,?); end;"); $stmt->bindParam(1, $hash, PDO::PARAM_STR, 32); $stmt->bindParam(2, $handle, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 32); @@ -574,17 +576,40 @@ class DatabaseConnection_oracle extends DatabaseConnection $handle= ORACLE_BLOB_PREFIX.$handle; //syslog(LOG_ERR,"returning handle: ".$handle); - + + // If enabled, write to cache. + if ($this->use_blob_cache) { + cache_set($handle, $value, 'cache_oracle_blobs'); + } + return $handle; } public function readBlob($handle) { - $handle= (int)substr($handle,strlen(ORACLE_BLOB_PREFIX)); - $stmt= parent::prepare("select content from blobs where blobid= ?"); - $stmt->bindParam(1, $handle, PDO::PARAM_INT, 32); - $stmt->execute(); - return $stmt->fetchObject()->content; + // First check if value is in cache. + if ($this->use_blob_cache) { + $cached = cache_get($handle, 'cache_oracle_blobs'); + + if ($cached) { + return $cached->data; + } + } + + // If not in cache, pull from db. + $handle = (int)substr($handle,strlen(ORACLE_BLOB_PREFIX)); + $stmt = parent::prepare("select content from blobs where blobid= ?"); + $stmt->bindParam(1, $handle, PDO::PARAM_INT, 32); + $stmt->execute(); + + $content = $stmt->fetchObject()->content; + + // If enabled, write to cache. + if ($this->use_blob_cache) { + cache_set($handle, $value, 'cache_oracle_blobs'); + } + + return $content; } public function cleanupFetchedValue($value) diff --git a/module/oracle/oracle.admin.inc b/module/oracle/oracle.admin.inc index 2738580..e8af713 100644 --- a/module/oracle/oracle.admin.inc +++ b/module/oracle/oracle.admin.inc @@ -4,8 +4,6 @@ function oracle_admin_settings() { - global $oracle_debug, $oracle_use_memcached, $oracle_cache_blobs; - $form['oracle-options'] = array( '#type' => 'fieldset', '#title' => t('Oracle driver options'), @@ -14,55 +12,21 @@ function oracle_admin_settings() '#collapsed' => FALSE, ); - $form['oracle-options']['debug'] = array( - '#type' => 'checkbox', - '#title' => t('Debug?'), - '#description' => t("output SQL statements with syslog (in the http server error log). To enable this option set \$"."GLOBALS['oracle_debug']= true; in your settings.php"), - '#default_value' => ($oracle_debug ? '1' : '0') + $form['oracle-options']['oracle_debug'] = array( + '#markup' => '

' . t('Debug: @enabled', array('@enabled' => variable_get('oracle_debug') ? t('Enabled') : t('Disabled'))) . '

' . t('Output SQL statements with syslog (in the http server error log). To enable this option set $conf["oracle_debug"] = TRUE; in your settings.php') . '

', ); $form['oracle-options']['cache'] = array( - '#type' => 'checkbox', - '#title' => t('Can we use cache_set / cache_get for statements ?'), - '#description' => t("You can enable to gain performance improvements. Don't use it unless you have memcached or cacherouter module active (cache_oracle table should be addressed to a memory engine for cacherouter). To enable this option set \$"."GLOBALS['oracle_use_memcached']= true; in your settings.php"), - '#default_value' => ($oracle_use_memcached ? '1' : '0') + '#markup' => '

' . t('Cache statements: @enabled', array('@enabled' => variable_get('oracle_use_memcached') ? t('Enabled') : t('Disabled'))) . '

' . t('Improves performance. Do not use unless you are using memcache. To enable this option set $conf["oracle_use_memcached"] = TRUE; in your settings.php') . '

', ); $form['oracle-options']['cacheb'] = array( - '#type' => 'checkbox', - '#title' => t('Can we use cache_set / cache_get for blobs ?'), - '#description' => t("You can enable to gain performance improvements. Don't use it unless you have memcached or cacherouter module active (cache_oracle_blobs table should be addressed to the file engine for cacherouter). To enable this option set \$"."GLOBALS['oracle_cache_blobs']= true; in your settings.php"), - '#default_value' => ($oracle_cache_blobs ? '1' : '0') + '#markup' => '

' . t('Cache blobs: @enabled', array('@enabled' => variable_get('oracle_cache_blobs') ? t('Enabled') : t('Disabled'))) . '

' . t('Improves performance. Do not use unless you are using memcache. To enable this option set $conf["oracle_cache_blobs"] = TRUE; in your settings.php') . '

', ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Save configuration'), - ); - $form['reset'] = array( - '#type' => 'submit', - '#value' => t('Reset to defaults'), - ); return $form; } -function oracle_admin_settings_submit($form, &$form_state) { - $op = $form_state['clicked_button']['#value']; - switch ($op) { - case "Save configuration": - $values = $form_state['values']; - - drupal_set_message(t('The configuration options have been saved.')); - - break; - case "Reset to defaults": - - drupal_set_message(t('The configuration options have been reset to their default values.')); - break; - } - -} - function oracle_admin_performance() { global $oracle_user;