Welcome Guest, Not a member yet? Register   Sign In
Database query caching not working
#2

[eluser]fchristant[/eluser]
I've done some further research and I think I found the problem, check out this code from CI's DB_driver.php file:

Code:
// Is query caching enabled?  If the query is a "read type"
// we will load the caching class and return the previously
// cached query if it exists
if ($this->cache_on == TRUE AND stristr($sql, 'SELECT'))
  {
  if ($this->_cache_init())
  {
   $this->load_rdriver();
   if (FALSE !== ($cache = $this->CACHE->read($sql)))
   {
   return $cache;
   }
  }
}
        
// Compile binds if needed
if ($binds !== FALSE)
{
$sql = $this->compile_binds($sql, $binds);
}

The query binding is done AFTER the cache checking. This seems to me like a bug, right? The cache checking mechanism can only know what cache file to look for when it knows the actual query. The actual query can only be known AFTER binding, not before.

As a quick check, I swapped these two blocks, performing cache checking after binding. This does solve the problem, the queries are cached now. However, a slight other problem occurs: connections to MySQL are still being made, although no queries are run:

87 Connect os4w@localhost on
87 Init DB os4w
87 Query SET NAMES 'utf8' COLLATE 'utf8_general_ci'
87 Quit
88 Connect os4w@localhost on
88 Init DB os4w
88 Query SET NAMES 'utf8' COLLATE 'utf8_general_ci'
88 Quit
89 Connect os4w@localhost on
89 Init DB os4w
89 Query SET NAMES 'utf8' COLLATE 'utf8_general_ci'
89 Quit

Am I right into thinking this is a serious bug? Any thoughts on how to make sure the MySQL connections are not being opened when a cached result is found?


Messages In This Thread
Database query caching not working - by El Forum - 05-21-2009, 05:52 AM
Database query caching not working - by El Forum - 05-21-2009, 06:13 AM
Database query caching not working - by El Forum - 05-21-2009, 06:39 AM
Database query caching not working - by El Forum - 05-21-2009, 06:49 AM
Database query caching not working - by El Forum - 05-21-2009, 07:08 AM
Database query caching not working - by El Forum - 05-21-2009, 11:30 AM
Database query caching not working - by El Forum - 05-21-2009, 11:38 AM
Database query caching not working - by El Forum - 05-21-2009, 12:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB