I am a newbie to php and cakephp, recently I was assigned a job to implement memcache in my app so that its performance can be increased. Can anyone suggest some documentation on this topic for me? Thanks.
-
2Are you sure you need memcache to scale your app? Premature optimization is the root of all evil. First write your app, then measure performance, then decide where the performance bottlenecks are, then decide where and what kind of caching or other techniques you need to use. First then use memcached, if necessary.sibidiba– sibidiba2011-01-06 09:12:24 +00:00Commented Jan 6, 2011 at 9:12
-
App is already written and working, we found the bottle necks (i.e. mysql queries) so now I decided to use memcached...Himanshu– Himanshu2011-01-06 09:49:20 +00:00Commented Jan 6, 2011 at 9:49
-
If your application is not distributed (i.e. only 1 application server), APC provides sufficient caching. You should have it installed regardless so that the byte code from the PHP interpreter gets cached. If you're using CakePHP 2.x, APC is already the default caching algorithm. You can optimize your app using the cache API described at book.cakephp.org/2.0/en/core-libraries/caching.htmlChris Hanson– Chris Hanson2013-10-23 14:33:49 +00:00Commented Oct 23, 2013 at 14:33
3 Answers
This might be a bit late ... but the Cake core has support for Memcached built in (at least in the latest versions, 2.0.x and 2.1).
Have a look at Config/core.php in your app, and you should see these lines (commented):
Cache::config('default', array(
'engine' => 'Memcache', //[required]
'duration' => 3600, //[optional]
'probability' => 100, //[optional]
'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
'servers' => array(
'127.0.0.1:11211' // localhost, default port 11211
), //[optional]
'persistent' => true, // [optional] set this to false for non-persistent connections
'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
));
You can uncomment these lines and test it out with a Memcached install. Make sure you have Memcached installed somewhere (localhost or elsewhere) and you are pointing to it.
Comments
Memcache is one of the supported Cache engines by the built-in Cache class. The Cache class is a wrapper for interacting with your Cache and you can read everything about it here: http://book.cakephp.org/2.0/en/core-libraries/caching.html
3 Comments
Warlock
Here is a more specific implementation of Memcache and Cakephp that may help with your bottle necks
Send your database on vacation by using CakePHP + Memcached