php - Caching multiple queries with memcached -


What is the way to cache many queries with memcached in PHP? Suppose a page has to present two questions, so do I need to use two different keys and use $ memcache twice?

Here's an example:

  $ Id = $ _POST ["id"]; $ Memcache = new memcache; $ Memcache- & gt; Connect ('local host', 11211) or die ("could not connect"); $ Dbh = New PDO ("mysql: host = $ hostname; dbname = $ databasename", $ username, $ password); $ Dbh- & gt; Set Attribution (PDO :: ATTRRAMOD, PDO :: ERRMODDEXEPEPS); $ Key1 = "{$ id} 1"; $ Key2 = "{$ id} 2"; $ Cache_result = array (); $ Cache_result = $ memcache- & gt; Get ($ key); $ Cache_result2 = array (); $ Cache_result2 = $ memcache- & gt; Get ($ key2); If ($ cache_result || $ cache_result2) {$ rows = $ cache_result; $ Rows 2 = $ cache_result2; } And {$ sql = "call load_thore (?);"; $ User = $ dbh- & gt; Ready ($ sql); $ User- & gt; Bind Value (1, 1, PDO :: paramic); $ Users & gt; Executed (); $ Rows = $ user- & gt; Get All (PDO :: FETCH_ASSOC); $ Memcache- & gt; Set ($ key, $ rows, MEMCACHE_COMPRESSED, 1200); $ Sql ​​= "call load_that (?)"; $ User = $ dbh- & gt; Ready ($ sql); $ User- & gt; Bind Value (1, 2, PDO :: Paramatti); $ Users & gt; Executed (); $ Rows = $ user- & gt; Get All (PDO :: FETCH_ASSOC); $ Memcache- & gt; Set ($ key2, $ rows 2, memkachuk compress, 1200); Print "NOT_CACHED"; }  

You can do this, but you want ...

If they are going to be cached at the same time, you can also:

  $ memcache-> set ('key', array ('result1' = & Gt; $ rows, 'result2' = & gt; $ rows 2), Mmacachuk Compress, 1200);  

This will cache both results in the same object and will require less calls for the memcatch, but the display will not be different meaningful.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -