Memcached - how to use it for multiple records returned from single SELECT operation?

I didn't get you. If you use php or . Net(Enyim client) you can store your result in to a object and set it in to memcached.(Client will serilized the object and store it in the memcached.) Following example will store one or more records given by the query Init Memcache, Try avoid multiple init if possible because this is a costly operation $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); mysql_pconnect("localhost","root",""); mysql_select_db("YOURDB"); $qurey="SELECT * FROM table where `firstname`='dasun';"; $key = md5($qurey); $get_result = $memcache->get($key); if ($get_result) { print_r($get_result); echo "It's a hit!

:)"; } else { $result = mysql_query($qurey); $row = mysql_fetch_array($result); print_r($row); // Store the result for a 5 minutes $memcache->set($key, $row, TRUE, 300); echo "Not a hit. :("; }.

I didn't get you. If you use php or . Net(Enyim client) you can store your result in to a object and set it in to memcached.(Client will serilized the object and store it in the memcached.) Following example will store one or more records given by the query.

//Init Memcache, Try avoid multiple init if possible because this is a costly operation $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); mysql_pconnect("localhost","root",""); mysql_select_db("YOURDB"); $qurey="SELECT * FROM table where `firstname`='dasun';"; $key = md5($qurey); $get_result = $memcache->get($key); if ($get_result) { print_r($get_result); echo "It's a hit! :)"; } else { $result = mysql_query($qurey); $row = mysql_fetch_array($result); print_r($row); // Store the result for a 5 minutes $memcache->set($key, $row, TRUE, 300); echo "Not a hit. :("; }.

It works great when there is no updates to the table, specifically the number of records having the same firstname. But if the table is being changed at high frequency, the cached data will be outdated in a very small time window, when that happens, would memcached still be usefu? – tom Aug 9 at 7:16 Another scenario, if there is another query $query2 = "SELECT * FROM table WHERE 'lastname' = 'eddie';" which would end up returning some records that overlap with some of records returned from $query = "SELECT * FROM table WHERE 'firstname' = 'dasun', can we still use the memcached as the way showcased above?

– tom Aug 9 at 7:30 Personally I don't use memchaced if the table is being changed at high frequency. If you do understand about the system you might able figure out which queries are more critical than others. Most of the time users may not notice we are giving the same result for 5 minutes.

– dasun Aug 9 at 8:10 For your second comment, No you can't. – dasun Aug 9 at 8:44.

I didn't get you. If you use php or . Net(Enyim client) you can store your result in to a object and set it in to memcached.

(Client will serilized the object and store it in the memcached. ).

Up vote 0 down vote favorite share g+ share fb share tw.

Memchached is useful for caching and looking up of single independent records. For the multiple records returned from doing a SELECT operation, how could I make good use of the memcached for caching and looking up later? Memcached link|improve this question asked Aug 8 '11 at 5:46tom1,244322 78% accept rate.

I didn't get you. If you use php or . Net(Enyim client) you can store your result in to a object and set it in to memcached.

(Client will serilized the object and store it in the memcached. ) Following example will store one or more records given by the query. //Init Memcache, Try avoid multiple init if possible because this is a costly operation $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); mysql_pconnect("localhost","root",""); mysql_select_db("YOURDB"); $qurey="SELECT * FROM table where `firstname`='dasun';"; $key = md5($qurey); $get_result = $memcache->get($key); if ($get_result) { print_r($get_result); echo "It's a hit!

:)"; } else { $result = mysql_query($qurey); $row = mysql_fetch_array($result); print_r($row); // Store the result for 5 minutes $memcache->set($key, $row, TRUE, 300); echo "Not a hit. :("; }.

It works great when there is no updates to the table, specifically the number of records having the same firstname. But if the table is being changed at high frequency, the cached data will be outdated in a very small time window, when that happens, would memcached still be usefu? – tom Aug 9 '11 at 7:16 Another scenario, if there is another query $query2 = "SELECT * FROM table WHERE 'lastname' = 'eddie';" which would end up returning some records that overlap with some of records returned from $query = "SELECT * FROM table WHERE 'firstname' = 'dasun', can we still use the memcached as the way showcased above?

– tom Aug 9 '11 at 7:30 Personally I don't use memchaced if the table is being changed at high frequency. If you do understand about the system you might able figure out which queries are more critical than others. Most of the time users may not notice we are giving the same result for 5 minutes.

– dasun Aug 9 '11 at 8:10 For your second comment, No you can't. – dasun Aug 9 '11 at 8:44 For the second comment, why did you say No? You will be storing 2 different result sets for 2 different keys!

The data might overlap and be redundant but Yes you can. – Binder Aug 9 '117 at 12:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions