Problema con el almacenamiento en caché de resultados de SQL
- Bogey
- Bogey


- Registrado: Jul 14, 2005
- Mensajes: 8212
- Loc: USA
- Status: Offline
Ok, tengo la siguiente función:
A ver dónde se comprueba si se almacena en caché? Al principio para ver si se debe devolver cerca de la final donde se comprueba si era necesario para almacenar en caché...
De todos modos, la función que en realidad se almacena en caché:
El problema estoy teniendo es cuando trato de ejecutar el SQL y el almacenamiento en caché se les almacena en caché como número entero. Yo var_dump ($ resultados) y se imprime int (1).
Puedo comprobar los archivos de caché y me dicen que: 1;
Cualquier ayuda?
PHP Código: [ Select ]
public function fetch_rowset($sql, $type = 'assoc')
{
// Checking if the SQL query was cached
if($this->cache_results === true)
{
// The name of the cached file
$sql_file = $this->cache_dir . md5($sql) . '.cache';
// Checking if the SQL file exists
if(file_exists($sql_file))
{
return unserialize(file_get_contents($sql_file));
}
}
// Creating a result resource
$results = $this->set_result_resource($sql, true);
// Initiating the result array
$result = array();
// Checking what type of result we want
if($type == 'assoc')
{
while($row = mysql_fetch_assoc($results))
{
$result[] = $row;
}
}
elseif($type == 'array')
{
while($row = mysql_fetch_array($results))
{
$result[] = $row;
}
}
elseif($type == 'object')
{
while($row = mysql_fetch_object($results))
{
$result[] = $row;
}
}
elseif($type == 'row')
{
while($row = mysql_fetch_row($results))
{
$result[] = $row;
}
}
else
{
while($row = mysql_fetch_assoc($results))
{
$result[] = $row;
}
}
// Checking if we need to free the result resource
if($this->free_result == true)
{
$this->free_result();
}
// Checking if we need to cache the result
if($this->cache_results === true)
{
return $this->cache_results($sql, $result);
}
// Returning the result (if not cached)
return ($type == 'object') ? (object) $result : $result;
}
{
// Checking if the SQL query was cached
if($this->cache_results === true)
{
// The name of the cached file
$sql_file = $this->cache_dir . md5($sql) . '.cache';
// Checking if the SQL file exists
if(file_exists($sql_file))
{
return unserialize(file_get_contents($sql_file));
}
}
// Creating a result resource
$results = $this->set_result_resource($sql, true);
// Initiating the result array
$result = array();
// Checking what type of result we want
if($type == 'assoc')
{
while($row = mysql_fetch_assoc($results))
{
$result[] = $row;
}
}
elseif($type == 'array')
{
while($row = mysql_fetch_array($results))
{
$result[] = $row;
}
}
elseif($type == 'object')
{
while($row = mysql_fetch_object($results))
{
$result[] = $row;
}
}
elseif($type == 'row')
{
while($row = mysql_fetch_row($results))
{
$result[] = $row;
}
}
else
{
while($row = mysql_fetch_assoc($results))
{
$result[] = $row;
}
}
// Checking if we need to free the result resource
if($this->free_result == true)
{
$this->free_result();
}
// Checking if we need to cache the result
if($this->cache_results === true)
{
return $this->cache_results($sql, $result);
}
// Returning the result (if not cached)
return ($type == 'object') ? (object) $result : $result;
}
- public function fetch_rowset($sql, $type = 'assoc')
- {
- // Checking if the SQL query was cached
- if($this->cache_results === true)
- {
- // The name of the cached file
- $sql_file = $this->cache_dir . md5($sql) . '.cache';
- // Checking if the SQL file exists
- if(file_exists($sql_file))
- {
- return unserialize(file_get_contents($sql_file));
- }
- }
- // Creating a result resource
- $results = $this->set_result_resource($sql, true);
- // Initiating the result array
- $result = array();
- // Checking what type of result we want
- if($type == 'assoc')
- {
- while($row = mysql_fetch_assoc($results))
- {
- $result[] = $row;
- }
- }
- elseif($type == 'array')
- {
- while($row = mysql_fetch_array($results))
- {
- $result[] = $row;
- }
- }
- elseif($type == 'object')
- {
- while($row = mysql_fetch_object($results))
- {
- $result[] = $row;
- }
- }
- elseif($type == 'row')
- {
- while($row = mysql_fetch_row($results))
- {
- $result[] = $row;
- }
- }
- else
- {
- while($row = mysql_fetch_assoc($results))
- {
- $result[] = $row;
- }
- }
- // Checking if we need to free the result resource
- if($this->free_result == true)
- {
- $this->free_result();
- }
- // Checking if we need to cache the result
- if($this->cache_results === true)
- {
- return $this->cache_results($sql, $result);
- }
- // Returning the result (if not cached)
- return ($type == 'object') ? (object) $result : $result;
- }
A ver dónde se comprueba si se almacena en caché? Al principio para ver si se debe devolver cerca de la final donde se comprueba si era necesario para almacenar en caché...
De todos modos, la función que en realidad se almacena en caché:
PHP Código: [ Select ]
private function cache_results($sql, $results)
{
// Generating the file name for the cache
$sql_file = $this->cache_dir . md5($sql) . '.cache';
// Creating the cache file
if(touch($sql_file))
{
file_put_contents($sql_file, serialize($results));
}
return $results;
}
{
// Generating the file name for the cache
$sql_file = $this->cache_dir . md5($sql) . '.cache';
// Creating the cache file
if(touch($sql_file))
{
file_put_contents($sql_file, serialize($results));
}
return $results;
}
- private function cache_results($sql, $results)
- {
- // Generating the file name for the cache
- $sql_file = $this->cache_dir . md5($sql) . '.cache';
- // Creating the cache file
- if(touch($sql_file))
- {
- file_put_contents($sql_file, serialize($results));
- }
- return $results;
- }
El problema estoy teniendo es cuando trato de ejecutar el SQL y el almacenamiento en caché se les almacena en caché como número entero. Yo var_dump ($ resultados) y se imprime int (1).
Puedo comprobar los archivos de caché y me dicen que: 1;
Cualquier ayuda?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- Anonymous
- Bot


- Registrado: 25 Feb 2008
- Mensajes: ?
- Loc: Ozzuland
- Status: Online
Noviembre 5th, 2010, 10:10 pm
- Bogey
- Bogey


- Registrado: Jul 14, 2005
- Mensajes: 8212
- Loc: USA
- Status: Offline
Todavía no he de poder encontrar una solución a este problema todavía. ¿Hay alguien aquí que pueda ayudarme a resolver este problema.
La función ha cambiado a lo siguiente:
La función ha cambiado a lo siguiente:
PHP Código: [ Select ]
public function fetch_rowset($sql, $type = 'assoc')
{
// Checking if the SQL query was cached
if($this->cache_results === true)
{
// The name of the cached file
$sql_file = $this->cache_dir . md5($sql) . '.cache';
// Checking if the SQL file exists
if(file_exists($sql_file))
{
return unserialize(file_get_contents($sql_file));
}
}
// Creating a result resource
$results = $this->set_result_resource($sql, true);
// Checking what type of result we want
if($type == 'assoc')
{
while($row = mysql_fetch_assoc($results))
{
$result = $row;
}
}
elseif($type == 'array')
{
while($row = mysql_fetch_array($results))
{
$result = $row;
}
}
elseif($type == 'object')
{
while($row = mysql_fetch_object($results))
{
$result = $row;
}
}
elseif($type == 'row')
{
while($row = mysql_fetch_row($results))
{
$result = $row;
}
}
else
{
while($row = mysql_fetch_assoc($results))
{
$result = $row;
}
}
// Checking if we need to free the result resource
if($this->free_result == true)
{
$this->free_result();
}
// Checking if we need to cache the result
if($this->cache_results === true)
{
$this->cache_result($sql, $result);
}
// Returning the result (if not cached)
return ($type == 'object') ? (object) $result : $result;
}
{
// Checking if the SQL query was cached
if($this->cache_results === true)
{
// The name of the cached file
$sql_file = $this->cache_dir . md5($sql) . '.cache';
// Checking if the SQL file exists
if(file_exists($sql_file))
{
return unserialize(file_get_contents($sql_file));
}
}
// Creating a result resource
$results = $this->set_result_resource($sql, true);
// Checking what type of result we want
if($type == 'assoc')
{
while($row = mysql_fetch_assoc($results))
{
$result = $row;
}
}
elseif($type == 'array')
{
while($row = mysql_fetch_array($results))
{
$result = $row;
}
}
elseif($type == 'object')
{
while($row = mysql_fetch_object($results))
{
$result = $row;
}
}
elseif($type == 'row')
{
while($row = mysql_fetch_row($results))
{
$result = $row;
}
}
else
{
while($row = mysql_fetch_assoc($results))
{
$result = $row;
}
}
// Checking if we need to free the result resource
if($this->free_result == true)
{
$this->free_result();
}
// Checking if we need to cache the result
if($this->cache_results === true)
{
$this->cache_result($sql, $result);
}
// Returning the result (if not cached)
return ($type == 'object') ? (object) $result : $result;
}
- public function fetch_rowset($sql, $type = 'assoc')
- {
- // Checking if the SQL query was cached
- if($this->cache_results === true)
- {
- // The name of the cached file
- $sql_file = $this->cache_dir . md5($sql) . '.cache';
- // Checking if the SQL file exists
- if(file_exists($sql_file))
- {
- return unserialize(file_get_contents($sql_file));
- }
- }
- // Creating a result resource
- $results = $this->set_result_resource($sql, true);
- // Checking what type of result we want
- if($type == 'assoc')
- {
- while($row = mysql_fetch_assoc($results))
- {
- $result = $row;
- }
- }
- elseif($type == 'array')
- {
- while($row = mysql_fetch_array($results))
- {
- $result = $row;
- }
- }
- elseif($type == 'object')
- {
- while($row = mysql_fetch_object($results))
- {
- $result = $row;
- }
- }
- elseif($type == 'row')
- {
- while($row = mysql_fetch_row($results))
- {
- $result = $row;
- }
- }
- else
- {
- while($row = mysql_fetch_assoc($results))
- {
- $result = $row;
- }
- }
- // Checking if we need to free the result resource
- if($this->free_result == true)
- {
- $this->free_result();
- }
- // Checking if we need to cache the result
- if($this->cache_results === true)
- {
- $this->cache_result($sql, $result);
- }
- // Returning the result (if not cached)
- return ($type == 'object') ? (object) $result : $result;
- }
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- Bogey
- Bogey


- Registrado: Jul 14, 2005
- Mensajes: 8212
- Loc: USA
- Status: Offline
- joebert
- Sledgehammer


- Registrado: Feb 10, 2004
- Mensajes: 13458
- Loc: Florida
- Status: Offline
- Bogey
- Bogey


- Registrado: Jul 14, 2005
- Mensajes: 8212
- Loc: USA
- Status: Offline
joebert escribió:
Me alegro de que todo salió. He mirado en este hilo un par de veces preguntando por qué la caché de consultas MySQL no fue suficiente caché. 
El problema estaba en cómo estaba la aplicación de la caché.
Yo estaba usando mi _get_ () que llama a mysql_num_rows (), que a su vez, se almacena en caché. Luego se pide a mysql_fetch_row y almacena en caché, así...el problema con esto es que el SQL es el mismo para ambas consultas.
Bueno, eso no era el problema, pero los dos trataron de escribir los resultados en el archivo de caché misma.
Con Ubuntu, tan pronto como se crea el archivo escrito, que son automáticamente chmodded como de sólo lectura, por lo que mysql_fetch_row regresaba int (1), ya que eso es lo que está en la caché después de mysql_num_rows.
He añadido _num para el SQL que almacena mysql_num_row como nombre de archivo md5 ($ sql ". _num")
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
Página 1 de 1
Para responder a este tema que necesita para ingresar o registrarse. Es gratis.
Publicar Información
- Total de mensajes en este tema: 5 mensajes
- Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 136 invitados
- No puede abrir nuevos temas en este Foro
- No puede responder a temas en este Foro
- No puede editar sus mensajes en este Foro
- No puede borrar sus mensajes en este Foro
- No puede enviar adjuntos en este Foro
