Page 1 of 1
Caching with APC
#1
Posted 22 December 2011 - 07:59 PM
Ok, so I'm now in the process of finally redoing out company website. THis time around we have a new server with APC enabled.
For caching I'd usually go down a file based router using pear cache lite, as it's simple and available to use on all servers.
In the past I've used APC briefly to cache a few arrays and variables - nothing major.
I've just come across a class that will cache the entire page output, using APC and then serve full pages from memory - which will obviously be a lot faster than a filoe basedf solution. See http://www.phpclasse...-using-APC.html
The pages on the site in question will be pretty static and will change weekly ish, but will be fairly complicated as the whole site is written using my CMS. So, the site would essentially always be served from cache until I manually clear it.
Anyway, can anyone forsee any issues with this?
For caching I'd usually go down a file based router using pear cache lite, as it's simple and available to use on all servers.
In the past I've used APC briefly to cache a few arrays and variables - nothing major.
I've just come across a class that will cache the entire page output, using APC and then serve full pages from memory - which will obviously be a lot faster than a filoe basedf solution. See http://www.phpclasse...-using-APC.html
The pages on the site in question will be pretty static and will change weekly ish, but will be fairly complicated as the whole site is written using my CMS. So, the site would essentially always be served from cache until I manually clear it.
Anyway, can anyone forsee any issues with this?
#2
Posted 01 January 2012 - 05:06 PM
APC is a good idea - however, what happens if memory is emptied on the server? Here is what I would recommend:
1. Check APC to see if the key/data exists
2. If #1 returns false, select from database.
3. After #2 save to memory via APC.
You don't need a special class to cache data, you could quite simply buffer the output of the view, example:
1. Check APC to see if the key/data exists
2. If #1 returns false, select from database.
3. After #2 save to memory via APC.
You don't need a special class to cache data, you could quite simply buffer the output of the view, example:
// Is it already saved in memory?
$content = apc_fetch('page_name');
if ($content) {
echo $content;
exit;
}
// otherwise query the database...
ob_start();
echo $data_from_database;
$data = ob_get_contents();
apc_store('page_name', $data);
This post has been edited by KieranA: 01 January 2012 - 05:06 PM
#3
Posted 01 January 2012 - 10:33 PM
KieranA, on 01 January 2012 - 05:06 PM, said:
APC is a good idea - however, what happens if memory is emptied on the server? Here is what I would recommend:
1. Check APC to see if the key/data exists
2. If #1 returns false, select from database.
3. After #2 save to memory via APC.
You don't need a special class to cache data, you could quite simply buffer the output of the view, example:
1. Check APC to see if the key/data exists
2. If #1 returns false, select from database.
3. After #2 save to memory via APC.
You don't need a special class to cache data, you could quite simply buffer the output of the view, example:
// Is it already saved in memory?
$content = apc_fetch('page_name');
if ($content) {
echo $content;
exit;
}
// otherwise query the database...
ob_start();
echo $data_from_database;
$data = ob_get_contents();
apc_store('page_name', $data);
Yer, that's essentially what the class does, but a little cleaner.
Just wondered if anyone saw any issues with this, as I'm caching whole pages using APC which will take up more memory.
#4
Posted 01 January 2012 - 10:41 PM
rallport, on 01 January 2012 - 10:33 PM, said:
Yer, that's essentially what the class does, but a little cleaner.
Just wondered if anyone saw any issues with this, as I'm caching whole pages using APC which will take up more memory.
Just wondered if anyone saw any issues with this, as I'm caching whole pages using APC which will take up more memory.
If it's only HTML then you should be fine - but to be sure you should run a quick audit on the site and figure out the overall size of the dataset.
This post has been edited by KieranA: 01 January 2012 - 10:43 PM
#5
Posted 02 January 2012 - 10:07 AM
That's the main thing I'm worried about really - haven't really been able to find any guidelines on it either. All the documentation seems to be for caching key/values
- ← How to automatically append text to a form field?
- Server Side (PHP, Databases, ASP.NET, etc)
- Internal Network →
Share this topic:
Page 1 of 1
Help















