Sorry for the simple question, just want to make sure I’m doing this right. How do I check a memcache variable expiration date and query my database again only if the expiration date hasn’t expired? Is empty() all that is needed?
here’s my code:
$memcache = new Memcache;
$memcache->connect('localhost', 11211);
$dbQuery=$memcache->get('dbQuery');
if(empty($dbQuery)){
$dbQuery=$this->db->query("SELECT * FROM items WHERE ...");
$memcache->set('dbQuery', $dbQuery, false, 60*60);
$dbQuery=$memcache->get('dbQuery');
}
else{
}
return $dbQuery;
I do it the following way:
get()returnsFALSEif the key is not found.http://www.php.net/manual/en/memcache.get.php