开发者

Does CakePHP have support for APC, XCache and others?

Does CakePHP have suppo开发者_如何学Pythonrt for APC, XCache and others?


In cake's /app/config/core.php ,there are some options for you to set the cache engines(version newer than 1.2).e.g

  APC (http://pecl.php.net/package/APC)

 Cache::config('default', array(
    'engine' => 'Apc', //[required]
    'duration'=> 3600, //[optional]
    'probability'=> 100, //[optional]
    'prefix' => Inflector::slug(APP_DIR) . '_', //[optional]  prefix every     cache file with this string
));


It should support APC as an opcode cache -- it's just PHP code, afterall.

And it seems there is an APC-related class to use APC as a cache for data : see ApcEngine.
See also, in the manual : 7.2.2 Cache Engines in Cake, in which it says there is support for APC, XCache, File, and memcached.


Just to add to the other good answers provided already, there are some tricks to get cake to use anything other than file cache for it's internal caching. This code will make cake use APC,Xcache, whatever for it's core cache (APC in this example)

Cache::config('_cake_core_', 
    array(
       'engine' => 'Apc',
       'duration'=> 3600,
       'probability'=> 100,
    )
);

Cake can also cache your models by putting this in your controllers/appcontroller.

var $persistModel = true;

However, models can only use file cache

These were all stolen from this article, which includes a bunch of ways to use cake's caching mechanisms to speed up your app

http://www.pseudocoder.com/archives/8-ways-to-speed-up-cakephp-apps

Also, as Pascal has mentioned, by installing and configuring APC, your PHP opcode is automatically cached.

For even more caching goodness, php supports memcache as an alternative to files as a session store, which is particularly useful in load balanced environments. An example of a single server implementation would be to put this in your ini

extension=memcache.so
session.save_handler = memcache
session.save_path = "tcp://127.0.0.1:11211?persistent=1"

And this in your core.php

Configure::write('Session.save', 'php');


In CakePhp 2.0 Apc is automatically detected and set. In your core.php you can find:

$engine = 'File'; 
if (extension_loaded('apc') && function_exists('apc_dec') && (php_sapi_name() !== 'cli' || ini_get('apc.enable_cli'))) {
    $engine = 'Apc';

}


Note that after CakePHP 2.2 ,auto APC detection is disabled.

In 2.2.1 APC was used, if detected: https://github.com/cakephp/cakephp/blob/2.2.1/app/Config/core.php

Since 2.3 default engine is "File". Latest stable /app/Config/core.php https://github.com/cakephp/cakephp/blob/2.4.4/app/Config/core.php#L352


As of 2.4.4 these are supported

  • File engine
  • APC
  • Wincache
  • XCache
  • Memcache
  • Redis

Documentation: http://book.cakephp.org/2.0/en/core-libraries/caching.html#caching

  • FileCache File cache is a simple cache that uses local files. It is the slowest cache engine, and doesn’t provide as many features for atomic operations. However, since disk storage is often quite cheap, storing large objects, or elements that are infrequently written work well in files. This is the default Cache engine for 2.3+

  • ApcCache APC cache uses the PHP APC extension. This extension uses shared memory on the webserver to store objects. This makes it very fast, and able to provide atomic read/write features. By default CakePHP in 2.0-2.2 will use this cache engine if it’s available.

  • Wincache Wincache uses the Wincache extension. Wincache is similar to APC in features and performance, but optimized for Windows and IIS.

  • XcacheEngine Xcache is a PHP extension that provides similar features to APC.

  • MemcacheEngine Uses the Memcache extension. Memcache provides a very fast cache system that can be distributed across many servers, and provides atomic operations.

  • RedisEngine Uses the phpredis extension. Redis provides a fast and persistent cache system similar to memcached, also provides atomic operations.


If you are curious about using which one. Check the development state of them.

  • APC: Last stable: 3.1.9, 14 may 2011, http://pecl.php.net/package/apc
  • Wincache: 1.3.5, 13 sept 2013, http://sourceforge.net/projects/wincache/files/
  • XCache: 3.1.0, 10 oct 2013, http://xcache.lighttpd.net/
  • Memcache: 2.2.7, 22 sep 2012, http://pecl.php.net/package/memcache
  • Redis: 2.8.4, 13 jan 2014, http://redis.io/download
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜