note 61821 deleted from function.memcache-add by nlopess
| From: | nlopess@php.net | Date: | Tue, 01 May 2007 13:26:08 +0000 |
| Subject: | note 61821 deleted from function.memcache-add by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126020@lists.php.net to get a copy of this message | ||
Note Submitter: adam dot alkins at gmail dot com
----
As the documentation notes, this function returns false if it doesn't replace an existing item
(You must have added the item before for replace to work). If you're writing a dynamic
application which for example caches data from an SQL database, your code should look like this.
<?php
if(!$mc->replace('foo', 'bar'))
{
$mc->add('foo', 'bar');
}
?>
This ensures that the memcache server is repopulated properly everytime it is restarted.