2011-03-05 37 views
0

我在做一個使用MVC體系結構的項目。我正在保持會話中的所有值。我的一位高級開發人員告訴我,這不是一個正確的過程,他建議我將所有值存儲在緩存中。如何在Memcache中存儲對象以及如何使用PHP檢索它

他對嗎?如果是的話,我怎麼能做到這一點使用PHP ...

+0

可能重複[如何使用memcache與php](http://stackoverflow.com/questions/4779523/how-to-use-memcache-with- php) – 2011-03-05 10:16:44

回答

6

內存緩存是不是一切答案,但可以顯着提高具有大量負載的Web應用程序頁面加載。

這個概念是將數據存儲爲內存中的鍵值對(一個memcache),並在必要時使用鍵檢索數據。

這裏是PHP的內存緩存設置和檢索數據的一個簡單的例子:

$memcache = new Memcache; 
$memcache->connect('192.168.1.2', 11211) or die ("Unable to connect"); 
$memcache->set(‘key1’, 'value1'); // Set some data 
$memcache->get('key1'); // Get some data 

閱讀上一些這樣的:

http://papermashup.com/using-memcache-with-php/

http://fschiettecatte.wordpress.com/2008/05/15/to-use-or-not-to-use-memcached-that-is-the-question/

http://www.majordojo.com/2007/03/memcached-howto.php

祝你好運,讓我知道如果你有任何更多的問題

+0

感謝您的支持Philo – Fero 2011-03-07 04:38:54

相關問題