使用Symfony2和条令进行缓存-使用哪一种?phpFastCache是一个选项吗?
这是一个关于基于Symfony(2.7)和Doctrine(2.5)构建的应用程序的一般问题和具体问题,该应用程序计划推送到两个不同的PHP PaaS平台 一般部分: 我正在本地开发最新的PHP版本(不想使用旧版本),但我的PHP PaaS平台的两个构建包只提供了现代的5.4 PHP 我想实现字节码缓存(当然)和对象/变量缓存 了解到APC在5.4之后不再有效(但仍然拥有Symfony提供的最佳“内置”支持),并且没有找到任何提供字节码和对象缓存的通用缓存机制,我最终尝试将其实现为我的缓存机制——我希望它能在这两个5.4平台上运行(在一种情况下仍然允许APC,在另一种情况下允许xcache) 在我遇到麻烦之前,如何使用Symfony/doctor运行phpfastcache: 有人知道有哪一个缓存模块是稳定的,由Heroku/Cloudfoundry(标准的PHP构建包-对我来说,构建我的一个构建包没有Paas的部分优势)支持,并且运行在>PHP5.4上,理想情况下支持字节码和对象缓存 特定部分: 看起来我很有希望 我试图通过以下方式使用此功能: 1)实现我的PhpFastCacheProvider.php 这旨在实现来自Doctrine CacheProvider以及来自Validator CacheInterface的所有方法使用Symfony2和条令进行缓存-使用哪一种?phpFastCache是一个选项吗?,php,symfony,caching,doctrine-orm,doctrine,Php,Symfony,Caching,Doctrine Orm,Doctrine,这是一个关于基于Symfony(2.7)和Doctrine(2.5)构建的应用程序的一般问题和具体问题,该应用程序计划推送到两个不同的PHP PaaS平台 一般部分: 我正在本地开发最新的PHP版本(不想使用旧版本),但我的PHP PaaS平台的两个构建包只提供了现代的5.4 PHP 我想实现字节码缓存(当然)和对象/变量缓存 了解到APC在5.4之后不再有效(但仍然拥有Symfony提供的最佳“内置”支持),并且没有找到任何提供字节码和对象缓存的通用缓存机制,我最终尝试将其实现为我的缓存机制—
<?php
namespace My\MyBundle\Cache;
use Doctrine\Common\Cache\CacheProvider;
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use phpFastCache;
class PhpFastCacheProvider extends CacheProvider implements CacheInterface
{
public function __construct()
{
if (extension_loaded('apc') && ini_get('apc.enabled') && strpos(PHP_SAPI, "CGI") === false) {
$driver = "apc";
} elseif (extension_loaded('xcache') && function_exists("xcache_get")) {
$driver = "xcache";
} else {
$driver = "auto";
}
phpFastCache::setup("storage", $driver);
}
public function doDelete($id)
{
__c()->delete($id);
}
public function doFlush()
{
__c()->clean();
}
public function doGetStats()
{
return __c()->stats();
}
public function has($class)
{
return $this->doContains($class);
}
public function doContains($id)
{
return __c()->isExisting($id);
}
public function read($class)
{
return $this->doFetch($class);
}
public function doFetch($id)
{
$a = __c();
$b = $this->doGetStats();
$value = __c()->get($id);
if ($value == null) {
return false;
}
return $value;
}
public function write(ClassMetadata $metadata)
{
$this->doSave($metadata->getClassName(), $metadata);
}
public function doSave($id, $data, $lifeTime = 0)
{
__c()->set($id, $data, ($lifeTime == 0) ? 24 * 3600 : $lifeTime);
}
3)更新config.yml以使用它
framework:
validation: {enable_annotations: true, cache: phpfastcache }
doctrine:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore
metadata_cache_driver:
type: service
id: phpfastcache
result_cache_driver:
type: service
id: phpfastcache
query_cache_driver:
type: service
id: phpfastcache
- xcache是本地安装的,甚至是针对PHPCLI运行的(通过从我的代码在xcache中设置一些变量并在xcache管理控制台中验证来检查)。 我还验证了$driver是“xcache”——这里没有问题
- symfony和doctrine启动-到目前为止没有问题
- 但是:因为我不完全理解phpFastCache和magic _c()是如何在任何时候被实例化的,只有“文件”被用作配置/存储,我不明白为什么
framework:
validation: {enable_annotations: true, cache: phpfastcache }
doctrine:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore
metadata_cache_driver:
type: service
id: phpfastcache
result_cache_driver:
type: service
id: phpfastcache
query_cache_driver:
type: service
id: phpfastcache