Can I use memcached as a Database

Marcus Bointon marcus at
Tue Sep 26 00:38:13 UTC 2006

On 26 Sep 2006, at 01:09, Junaid N. Sahibzada wrote:

> Now if i have another item to add to the cache, how do i add it to  
> the cache?

Just call set with the new item.

> 2. I would basically want to have a database of URLS in my main  
> memory which i can quickly query, index, update, delete and modify.
> Is this possible with memcache?

Possible yes, sensible, probably not. Searching memcached is very  
limited - exact match on one key is all you get (AFAIK). Seems like  
you should add your items individually so that they can be found and  
retrieved individually too. Lose your integer key, make your URL the  
key, don't serialize (memcache will do it for you) and if you're  
really storing only 'yes' and 'no' for each URL, I'd suggest you  
change that to a Boolean value.

$URLarray = array( '1'=>array('','Yes'),
                    '3'=>array('', 'No'),

foreach ($URLarray as $key => $value) {
clsMem::getMem()->set($value[0], $value[1] == 'Yes', true, 600) or  
die ("Could not write to the cache");

Now you can add more URLs very easily:

clsMem::getMem()->set($newurl, true, true, 600) or die ("Could not  
write to the cache");

Finding them is as simple as:

$value = clsMem::getMem()->get($url);

Marcus Bointon
Synchromedia Limited: Creators of
marcus at |

More information about the memcached mailing list