Added $nocache parameter

Fixed typo in caching
Excluded caching for MySQL-Authentication & /poll-log/
This commit is contained in:
Daniel Preussker
2015-09-30 15:20:06 +00:00
parent a321ba1bf6
commit afdbb2406d
6 changed files with 41 additions and 40 deletions
+15 -15
View File
@@ -239,10 +239,10 @@ function dbDelete($table, $where=null, $parameters=array()) {
* */
function dbFetchRows($sql, $parameters=array()) {
function dbFetchRows($sql, $parameters=array(), $nocache=false) {
global $db_stats, $config;
if ($config['memcached']['enable']) {
if ($config['memcached']['enable'] && $nocache === false) {
$result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters)));
if (!empty($result)) {
return $result;
@@ -259,7 +259,7 @@ function dbFetchRows($sql, $parameters=array()) {
}
mysqli_free_result($result);
if ($config['memcached']['enable']) {
if ($config['memcached']['enable'] && $nocache === false) {
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']);
}
return $rows;
@@ -284,8 +284,8 @@ function dbFetchRows($sql, $parameters=array()) {
* */
function dbFetch($sql, $parameters=array()) {
return dbFetchRows($sql, $parameters);
function dbFetch($sql, $parameters=array(), $nocache=false) {
return dbFetchRows($sql, $parameters, $nocache);
/*
// for now, don't do the iterator thing
$result = dbQuery($sql, $parameters);
@@ -306,10 +306,10 @@ function dbFetch($sql, $parameters=array()) {
* */
function dbFetchRow($sql=null, $parameters=array()) {
function dbFetchRow($sql=null, $parameters=array(), $nocache=false) {
global $db_stats, $config;
if ($config['memcached']['enable']) {
if ($config['memcached']['enable'] && $nocache === false) {
$result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters)));
if (!empty($result)) {
return $result;
@@ -326,8 +326,8 @@ function dbFetchRow($sql=null, $parameters=array()) {
$db_stats['fetchrow_sec'] += number_format(($time_end - $time_start), 8);
$db_stats['fetchrow']++;
if ($config['memcached']['enable']) {
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']);
if ($config['memcached']['enable'] && $nocache === false) {
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']);
}
return $row;
}
@@ -345,11 +345,11 @@ function dbFetchRow($sql=null, $parameters=array()) {
* */
function dbFetchCell($sql, $parameters=array()) {
function dbFetchCell($sql, $parameters=array(), $nocache=false) {
global $db_stats, $config;
$time_start = microtime(true);
$row = dbFetchRow($sql, $parameters);
$row = dbFetchRow($sql, $parameters, $nocache);
if ($row) {
return array_shift($row);
// shift first field off first row
@@ -371,11 +371,11 @@ function dbFetchCell($sql, $parameters=array()) {
* */
function dbFetchColumn($sql, $parameters=array()) {
function dbFetchColumn($sql, $parameters=array(), $nocache=false) {
global $db_stats;
$time_start = microtime(true);
$cells = array();
foreach (dbFetch($sql, $parameters) as $row) {
foreach (dbFetch($sql, $parameters, $nocache) as $row) {
$cells[] = array_shift($row);
}
@@ -396,9 +396,9 @@ function dbFetchColumn($sql, $parameters=array()) {
*/
function dbFetchKeyValue($sql, $parameters=array()) {
function dbFetchKeyValue($sql, $parameters=array(), $nocache=false) {
$data = array();
foreach (dbFetch($sql, $parameters) as $row) {
foreach (dbFetch($sql, $parameters, $nocache) as $row) {
$key = array_shift($row);
if (sizeof($row) == 1) {
// if there were only 2 fields in the result