Welcome Guest, Not a member yet? Register   Sign In
Database Caching - turning on/off with if/else isn't working
#1

[eluser]tinawina[/eluser]
I posted this yesterday within a thread I started titled "Database Cache - automatically "ping" pages on database update to create new cache files?" (http://ellislab.com/forums/viewthread/224464). I'm reposting as a separate thread because this is really a different problem than the one I originally wanted help with. Here's the problem.

Our queries are generated dynamically according to the URL string. We only want to cache a particular query. I can determine that query using one variable in my script. I am trying to set up an if/else that says: if this query is for X pages turn on caching, otherwise do not cache. Here's what I've got but it doesn't work (I am using $this->CI because this is all happening in a library file using CI v.2.1.2):
Code:
function fetch_results($query, $field = '') // $field comes from the URL, eg., http://mysite.org/field/X
{
$this->CI->db->cache_off(); // caching should be off to begin with

if ($field == 'X') // here I'm determining which query I'm running - if X then turn caching on
{
  $this->CI->db->cache_on();
}
$query = $this->CI->db->query($query);
I've also set this up like so but this also doesn't work:
Code:
function fetch_results($query, $field = '')
{
if ($field == 'X')
{
  $this->CI->db->cache_on();
}
else
{
  $this->CI->db->cache_off();
}
$query = $this->CI->db->query($query);


Any help/insight is greatly appreciated!


Messages In This Thread
Database Caching - turning on/off with if/else isn't working - by El Forum - 09-18-2012, 05:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB