I have never used memcache before now so please excuse my inexperience. Although it is pretty self explanatory, I would like to make sure I am using the built in functions correctly as I am creating a class that will be used commercially so it must be correctly coded and efficient.
I have several questions but as they are very basic I felt it would be alright to combine them into one Stackoverflow question.
If they require an essay answer, please dont bother and I will post it up as a separate question
- When would I need to use
memcache::addServer
and what is the difference between this andmemcache::connect
? - Does memcache overwrite stored values if it runs out of memory, even if the item has not yet expired?
- What would I use
memcache::getExtendedStats
for? - How do I check to see if a connection to memcache already exists and if not, create a connection?
- If I have my usual memcache server of 'localhost' set up, how would I go about setting up another memcache server on my same dedicated server?
- Apart from more memory, what is the benefit of having more than one memcache server?
- Should I check for memcache server updates regularly?
- Does it use a lot of memory to run memcache::connect at the beginning of each page, even if I am not using it?
- When am I likely to return errors and how do I catch these?
- Most importantly, if I am using memcache within another class that has several methods that may be called more then once per script, how should I go about initialising the object and connecting to the server within each method?
My guess for the last question would be to do it like so:
class test {
public function blah(){
// Make sure the memcache object is accessible
global $memcache;
// Do something ...
// Save result in memcache
$memcache->set(...);
}
public function foo(){
// Do something ...
// No use for memcache
}
}
// Initialise each class
$test = new test;
$memcache = new memcache;
$memcache->connect(...);
// Call some methods from the test class
$test->blah();
$test->foo();
$test->blah();
As you can see in the above example, I connect to the memcache server at the beginning of the script. If I was to include this at the beginning of every page, even on pages that do not use memcache, would this increase the response time a lot or minimal amounts? Hence, question 8!