Php APCu适配器&;Symfony 3.3->;错误

Php APCu适配器&;Symfony 3.3->;错误,php,symfony,service,controller,adapter,Php,Symfony,Service,Controller,Adapter,我正在尝试将APCu插入Symfony 3.3测试项目。 当我将ApcuAdapter添加到AppKernel.php时,我收到一个错误。 以下是我所做工作的清单: 在/app/AppKernel.php中,我在公共函数registerBundles()中的$bundles中添加了一个“新”行: 打开项目的站点。它显示了一个错误: 试图调用类“Symfony\Component\Cache\Adapter\ApcuAdapter”中名为“getName”的未定义方法 (/表示项目的根文件夹)

我正在尝试将APCu插入Symfony 3.3测试项目。 当我将
ApcuAdapter
添加到
AppKernel.php
时,我收到一个错误。 以下是我所做工作的清单:

  • /app/AppKernel.php
    中,我在
    公共函数registerBundles()中的
    $bundles
    中添加了一个“新”行:

  • 打开项目的站点。它显示了一个错误:

  • 试图调用类“Symfony\Component\Cache\Adapter\ApcuAdapter”中名为“getName”的未定义方法

    /
    表示项目的根文件夹)


    请告诉我为什么会发生此错误,以及如何将此适配器插入symfony框架。谢谢。

    我已经在框架的网站上找到了解决方案

    不知何故,我们不应该使用
    适配器
    ,而应该使用
    简单的
    。 我觉得很不合逻辑

    因此,该服务现在可以正常工作,并且看起来是这样的:

        <?php
    
        namespace AppBundle\Service;
    
        use Symfony\Component\Cache\Simple\ApcuCache;
    
        class ApcuTester
        {
            public function __construct
            (
            )
            {
    
            }
    
            public function testMe()
            {
                $cache = new ApcuCache();
    
                $TestVar_dv = 0;
                $TestVar_vn = 'TestVar';
                $TestVar = NULL;
    
                //$cache-> deleteItem($TestVar_vn); // dbg
    
                // Read
                if ( $cache->hasItem($TestVar_vn) )
                {
                    $TestVar = $cache->get($TestVar_vn);
                }
                else
                {
                    $cache->set($TestVar_vn, $TestVar_dv);
                    $TestVar = $TestVar_dv;
                }
    
                // Modify
                $TestVar++;
    
                // Save
                $cache->set($TestVar_vn, $TestVar);
    
                // Return
                return $TestVar;
            }
        }
    

    这个适配器本身不是框架的一部分吗?应该没有必要添加它。另外,从某种意义上说,该适配器不是一个捆绑包,您可以将它添加到
    AppKernel.php
    中的
    registerBundles()
    ,如果它是嵌入式的,那么如何从symfony 3.3运行
    apcu\u exists
    函数?
        <?php
    
        namespace AppBundle\Service;
    
        use Symfony\Component\Cache\Simple\ApcuCache;
    
        class ApcuTester
        {
            public function __construct
            (
            )
            {
    
            }
    
            public function testMe()
            {
                $cache = new ApcuCache();
    
                $TestVar_dv = 0;
                $TestVar_vn = 'TestVar';
                $TestVar = NULL;
    
                //$cache-> deleteItem($TestVar_vn); // dbg
    
                // Read
                if ( $cache->hasItem($TestVar_vn) )
                {
                    $TestVar = $cache->get($TestVar_vn);
                }
                else
                {
                    $cache->set($TestVar_vn, $TestVar_dv);
                    $TestVar = $TestVar_dv;
                }
    
                // Modify
                $TestVar++;
    
                // Save
                $cache->set($TestVar_vn, $TestVar);
    
                // Return
                return $TestVar;
            }
        }
    
        <?php
    
        namespace AppBundle\Controller;
    
        use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
        use Symfony\Bundle\FrameworkBundle\Controller\Controller;
        use Symfony\Component\HttpFoundation\Request;
    
        use AppBundle\Service\MessageGenerator;
        use AppBundle\Service\ApcuTester;
    
        class LuckyController extends Controller
        {
            /**
            * @Route("/lucky/number", name="lucky")
            */
            public function numberAction
            (
                Request $request, 
                MessageGenerator $messageGenerator,
                ApcuTester $apcuTester
            )
            {
                $lucky_number = mt_rand(0, 100);
    
                $message = $messageGenerator->getHappyMessage();
    
                $testvar = $apcuTester->testMe();
    
                $tpl = 'default/lucky_number.html.twig';
                $tpl_vars = 
                [
                    'lucky_number' => $lucky_number,
                    'message' => $message,
                    'testvar' => $testvar
                ];
    
                return $this->render($tpl, $tpl_vars);
            }
        }