CakePHP 支持 APC、XCache 等吗?

发布于 2024-08-28 16:27:00 字数 32 浏览 14 评论 0原文

CakePHP 支持 APC、XCache 等吗?

Does CakePHP have support for APC, XCache and others?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

季末如歌 2024-09-04 16:27:00

在cake的 /app/config/core.php 中,有一些选项供您设置缓存引擎(版本高于1.2)。例如

  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
));

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
));
够运 2024-09-04 16:27:00

它应该支持 APC 作为操作码缓存——毕竟它只是 PHP 代码。

似乎有一个与 APC 相关的类使用 APC 作为数据缓存:请参阅 ApcEngine

另请参阅手册中:7.2.2 中的缓存引擎Cake,其中表示支持 APC、XCache、File 和 memcached。

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.

偏爱自由 2024-09-04 16:27:00

只是为了添加已经提供的其他好的答案,有一些技巧可以让 cake 使用文件缓存以外的任何内容来进行内部缓存。这段代码将使cake使用APC,Xcache,无论它的核心缓存(本例中是APC)

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

Cake还可以通过将其放入控制器/应用程序控制器来缓存您的模型。

var $persistModel = true;

然而,模型只能使用文件缓存

这些都是从这篇文章中盗来的,其中包括一堆使用cake的缓存机制来加速你的应用程序的方法

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

另外正如 Pascal 所提到的,通过安装和配置 APC,您的 PHP 操作码会自动缓存。

为了获得更多的缓存优势,php 支持 memcache 作为文件会话存储的替代方案,这在负载平衡环境中特别有用。单个服务器实现的一个示例是将其放入您的 ini

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

并将其放入您的 core.php

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

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');
星光不落少年眉 2024-09-04 16:27:00

在 CakePhp 2.0 中,Apc 会被自动检测和设置。在你的 core.php 中你可以找到:

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

}

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';

}

三月梨花 2024-09-04 16:27:00

请注意,在 CakePHP 2.2 之后,自动 APC 检测被禁用。

在 2.2.1 中使用了 APC,如果检测到: https: //github.com/cakephp/cakephp/blob/2.2.1/app/Config/core.php

从 2.3 开始默认引擎是“File”。最新稳定 /app/Config/core.php https://github.com/cakephp/cakephp/blob/2.4.4/app/Config/core.php#L352


从 2.4.4 开始,支持这些

  • 文件引擎
  • APC
  • Wincache
  • XCache
  • Memcache
  • Redis

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

  • FileCache 文件缓存是使用本地文件的简单缓存。它是最慢的缓存引擎,并且不提供尽可能多的原子操作功能。然而,由于磁盘存储通常非常便宜,因此在文件中存储大型对象或不经常写入的元素效果很好。这是 2.3+ 的默认缓存引擎

  • ApcCache APC 缓存使用 PHP APC 扩展。此扩展使用网络服务器上的共享内存来存储对象。这使得它非常快,并且能够提供原子读/写功能。默认情况下,2.0-2.2 中的 CakePHP 将使用此缓存引擎(如果可用)。

  • Wincache Wincache 使用Wincache 扩展。 Wincache 在功能和性能上与 APC 类似,但针对 Windows 和 IIS 进行了优化。

  • XcacheEngine Xcache 是一个 PHP 扩展,提供与 APC 类似的功能。

  • MemcacheEngine 使用 Memcache 扩展。 Memcache 提供了一个非常快速的缓存系统,可以分布在许多服务器上,并提供原子操作。

  • RedisEngine 使用 phpredis 扩展。 Redis 提供了类似于 memcached 的快速且持久的缓存系统,也提供原子操作。


如果您好奇使用哪一个。检查它们的开发状态。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文