Hi Marcus,<br><br>Thank you very much for replying.<br><br>I am using your code and it seems its not working.<br><br>Here is the first script which is adding to the cache.<br><br><?php <br><br> <span style="font-weight: bold; font-style: italic;">class clsMem extends Memcache</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> {</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> </span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> static private $m_objMem = NULL;</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> </span><br style="font-weight: bold;
font-style: italic;"><span style="font-weight: bold; font-style: italic;"> static function getMem()</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> {</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> </span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> if (self::$m_objMem == NULL)</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> </span><br
style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> {</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> </span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> self::$m_objMem = new Memcache;</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;">
self::$m_objMem->connect('localhost', 11211) or die ("The memcached server");</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> </span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> }</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> return self::$m_objMem;</span><br style="font-weight: bold; font-style: italic;"><span
style="font-weight: bold; font-style: italic;"> }</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> }</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> </span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> $URLarray = array( '1'=>array('yahoo.com','Yes'),</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> '2'=>array('hotmail.com','Yes'),</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style:
italic;"> '3'=>array('cnn.com', 'No'),</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> '4'=>array('bbc.co.uk','Yes'),</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> '5'=>array('pctool.com','Yes'),);</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> </span><br style="font-weight: bold; font-style:
italic;"><span style="font-weight: bold; font-style: italic;"> $unit = 1;</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> </span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> foreach ($URLarray as $key => $value)</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> {</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;"> clsMem::getMem()->set($value[0], $value[1] == 'Yes', true, 600) or die ("Could not write to the cache");</span><br style="font-weight: bold; font-style: italic;"><span
style="font-weight: bold; font-style: italic;"> }</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;">?></span><br><br><br>And here is the second script which is trying to access the cache<br><br><span style="font-weight: bold; font-style: italic;"><?php</span><br style="font-weight: bold; font-style: italic;"><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;">include_once("memtest.php");</span><br style="font-weight: bold; font-style: italic;"><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;">$MyStringURL = clsMem::getMem()->get("URL") or die ("Couldn't find the requested URL item in the cache!");</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;">echo $MyStringURL;</span><br style="font-weight: bold;
font-style: italic;"><span style="font-weight: bold; font-style: italic;">echo "\n";</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;">$MyStringUnit = clsMem::getMem()->get("unit") or die ("Couldn't find the Unit item in the cache!");</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;">echo $MyStringUnit;</span><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;">echo "\n";</span><br style="font-weight: bold; font-style: italic;"><br style="font-weight: bold; font-style: italic;"><span style="font-weight: bold; font-style: italic;">?></span><br><br><br>And here is the output i get when i try to access the second script.<br><br>Array Couldn't find the Unit item in the cache!<br><br>Not only it doesnt update the variable $unit but it is also not returning the correct array items.<br><br>Can you please
help?<br><br>Thanks<br><br><br><b><i>Marcus Bointon <marcus@synchromedia.co.uk></i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> <br>On 26 Sep 2006, at 01:09, Junaid N. Sahibzada wrote:<br><br>> Now if i have another item to add to the cache, how do i add it to <br>> the cache?<br><br>Just call set with the new item.<br><br>> 2. I would basically want to have a database of URLS in my main <br>> memory which i can quickly query, index, update, delete and modify.<br>><br>> Is this possible with memcache?<br><br>Possible yes, sensible, probably not. Searching memcached is very <br>limited - exact match on one key is all you get (AFAIK). Seems like <br>you should add your items individually so that they can be found and <br>retrieved individually too. Lose your integer key, make your URL the <br>key, don't serialize (memcache will do it for you) and if you're
<br>really storing only 'yes' and 'no' for each URL, I'd suggest you <br>change that to a Boolean value.<br><br>$URLarray = array( '1'=>array('yahoo.com','Yes'),<br> '2'=>array('hotmail.com','Yes'),<br> '3'=>array('cnn.com', 'No'),<br> '4'=>array('bbc.co.uk','Yes'),<br> '5'=>array('pctool.com','Yes'),);<br><br>foreach ($URLarray as $key => $value) {<br>clsMem::getMem()->set($value[0], $value[1] == 'Yes', true, 600) or <br>die ("Could not write to the cache");<br>}<br><br>Now you can add more URLs very easily:<br><br>clsMem::getMem()->set($newurl, true, true, 600) or die ("Could not <br>write to the cache");<br><br>Finding them is as simple as:<br><br>$value = clsMem::getMem()->get($url);<br><br>Marcus<br>-- <br>Marcus Bointon<br>Synchromedia Limited: Creators of http://www.smartmessages.net/<br>marcus@synchromedia.co.uk |
http://www.synchromedia.co.uk/<br><br><br></blockquote><br><BR><BR><div style="font-family: arial;"> <div> <div> <div> <div> <div> <div> <div> <div> <div> <div> <div> <div> <div><strong>Junaid N. Sahibzada</strong></div> <div><strong>Cell # (+61) 404 998 494 </strong></div> <div><strong>Student MSc Internetworking, UTS, Australia</strong></div> <div><strong>Bachelor of Information Technology, NUST, Pakistan</strong></div></div></div></div></div></div></div></div></div></div></div></div></div></div><p> 
                <hr size=1>Stay in the know. Pulse on the new Yahoo.com. <a href="http://us.rd.yahoo.com/evt=42974/*http://www.yahoo.com/preview"> Check it out.</a>