Can I use memcached as a Database
Marcus Bointon
marcus at synchromedia.co.uk
Tue Sep 26 08:52:32 UTC 2006
On 26 Sep 2006, at 02:33, Junaid N. Sahibzada wrote:
> <?php
>
> include_once("memtest.php");
>
> $MyStringURL = clsMem::getMem()->get("URL") or die ("Couldn't find
> the requested URL item in the cache!");
> echo $MyStringURL;
> echo "\n";
> $MyStringUnit = clsMem::getMem()->get("unit") or die ("Couldn't
> find the Unit item in the cache!");
> echo $MyStringUnit;
> echo "\n";
>
> ?>
In each case, you're looking for a single key called either 'URL' or
'unit', neither of which exist. My suggestion was that you store each
URL as its own key, e.g.:
clsMem::getMem()->set('bbc.co.uk', true, true, 600) or die ("Could
not write to the cache");
Then to retrieve that value:
$unit = clsMem::getMem()->get('bbc.co.uk');
One problem is that it's not clear what you're trying to achieve.
Sticking everything in a single key is not really using memcached as
a database at all, which is what you asked for.
If you wanted to preserve all the data you initially posted about,
you'd need to make multiple keys for each entry, e.g. for the
('1'=>array('yahoo.com','Yes') entry:
clsMem::getMem()->set('URL:1', 'yahoo.com', true, 600) or die
("Could not write to the cache");
clsMem::getMem()->set('unit:1', 'yes', true, 600) or die ("Could not
write to the cache");
Then you could retrieve them by:
$URL = clsMem::getMem()->get('URL:1');
$unit = clsMem::getMem()->get('unit:1');
Any clearer?
Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
marcus at synchromedia.co.uk | http://www.synchromedia.co.uk/
More information about the memcached
mailing list