How to use ZendOpCache for Doctrine2 cache?

2019-02-13 06:47发布

I have installed PHP 5.5.1 in my development environment, and also have config Zend OpCache as Cache provider. Everything is working on the server with the new version and settings, but inside my symfony 2 project I have the Doctine2 cache to store some "static" data (countries, languages, etc) and it not works with Opcache.

Until today, I was using the Doctrine\Common\Cache\ApcCache class to work with the cache of Doctrine2 using APC, but seems that does not exists a class to work with OpCache.

This is my config.yml for APC cache:

# Services
services:
    cache:
        class: Doctrine\Common\Cache\ApcCache

Now, with OpCache I have tried to use ZendDataCache to deal with cache system, but does not work:

# Services
services:
    cache:
        class: Doctrine\Common\Cache\ZendDataCache

I get this error, so I assume that ZendDataCache class is not for OpCache:

FatalErrorException: Error: Call to undefined function Doctrine\Common\Cache\zend_shm_cache_fetch() in /var/www/meediam/src/vendor/doctrine/common/lib/Doctrine/Common/Cache/ZendDataCache.php line 38

Finally I have configured the ArrayCache, and it works, but without cache system behind.

So the question is, Anyone know how to use Zend OpCache with Doctrine 2 Cache?

PS: I am using Symfony 2.3.2

2条回答
祖国的老花朵
2楼-- · 2019-02-13 07:16

Adding my comment as an answer.

PHP's OpCache is not a full blown cache as APC It is a simply opcode cache. If you want to store custom data just like you would with the old APC you can use Joe Watkins' APCu: https://github.com/krakjoe/apcu.

There is also yac and memcache.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-02-13 07:24

You can actually use OpCache indirectly via PhpFileCache

查看更多
登录 后发表回答