内容管理框架MODX提供了使用APC作为缓存引擎的选项。我发现我可以将其迁移到APCu。
我复制并编辑了所有代码,以便我现在有第二个选项,它提供APCu作为缓存引擎。由于我的PHP技能在过去几年已经减少,我正在努力用正确的方法来重写构造函数。
原始代码是这样的:
class xPDOAPCCache extends xPDOCache {
public function __construct(& $xpdo, $options = array()) {
parent :: __construct($xpdo, $options);
if (function_exists('apc_exists')) {
$this->initialized = true;
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOAPCCache[{$this->key}]: Error creating APC cache provider; xPDOAPCCache requires the APC extension for PHP, version 2.0.0 or later.");
}
}
[...]
我重写了这样:
class xPDOAPCuCache extends xPDOCache {
public function __construct(& $xpdo, $options = array()) {
parent :: __construct($xpdo, $options);
if (function_exists('apcu_exists')) {
$this->initialized = true;
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOAPCuCache[{$this->key}]: Error creating APCu cache provider; xPDOAPCuCache requires the APCu extension for PHP.");
}
}
[...]
这不起作用,因为APCu没有采用与APC相同的参数。 (见http://php.net/manual/de/apciterator.construct.php和http://php.net/manual/de/apcuiterator.construct.php)
如何编辑此构造函数以使我的CMF与APCu一起作为缓存引擎?
您的代码示例似乎根本没有引用APCIterator?因此很难说它需要做出哪些改变。
我建议你看看apcu_bc,它在APCu之上提供了与APC API兼容的层。我不确定迭代器,但我已经成功使用了这个包很长一段时间,直到我逐渐迁移到本机APCu API。