• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database Cache - automatically "ping" pages on database update to create new cache files?

#1
[eluser]tinawina[/eluser]
The result set for some of my queries numbers in the thousands and so pages were taking a huge amount of time to load. I turned on database caching and things are zipping along at a terrific pace. Phew!

Brief background: We collect and share publications posted to our site by our users. People can log into our site and add a publication anytime. We check the records they create and if they meet our criteria we make them available on the site. I understand that I can set things up so that when we approve something for display we run $this->db->cache_delete() to remove the old cache file. Is there a way to automatically cache the new page query as well?

I guess we could add a display of a link to the page in question right after updating our database that says something like "Click <here> to update the database cache".... but if I can automate this so as not to have to rely on human interaction (or non-interaction -- people do make mistakes) that would be great.

Thanks for your ideas!

#2
[eluser]tinawina[/eluser]
One other thing -- our queries are generated dynamically according to the URL string. We only want to cache a particular query. I can isolate 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):
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!

#3
[eluser]tinawina[/eluser]
I know I'm hogging up bandwidth with this problem of mine - sorry! Just in a bit of a hurry to solve this.

Does anyone see anything wrong with running a script that loops through all pages that need a database cache -- 41 total (that won't change as it's the taxonomy we use for all publications) using PHP's "system" function to create my cache files?
Code:
$array = ('this', 'that', 'other');
foreach ($array as $value)
{
   system("GET http://mysite.org/publications/profile/" . $value);
}
This pulls up the exact same page a visitor would pull up and create the cache file I need to have in place so that visitors don't have incredibly long load times if they are first to pull up a page. I tried this and it took awhile to complete, but in the end did create the cache files.

So when we approve a publication I would run a $this->db->cache_delete_all(), and then run a script that does this loop through. What do you think?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.