Storing Symfony 2 cache elsewere?

后端 未结 2 1706
小鲜肉
小鲜肉 2021-01-14 06:59

Is there a way to store symfony 2 cache (app/cache) somewhere else other than the filesystem? Memcache, S3, or something? Any built-in option?

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-14 07:27

    You can only move it outside of the project directory by overloading getCacheDir() method in the AppKernel class.

    What's the point of moving it to Memcache? Contents of this directory is most of the time "compiled" classes and templates. Those files are put into memory anyway (APC does that).

    Edit: On development, it's harder to avoid I/O, but you can easily move Symfony's cache dir to memory by overriding AppKernel's getCacheDir() and getLogDir() methods to point them to /dev/shm:

    class AppKernel extends Kernel
    {
        // ...
    
        public function getCacheDir()
        {
            if (in_array($this->environment, array('dev', 'test'))) {
                return '/dev/shm/appname/cache/' .  $this->environment;
            }
    
            return parent::getCacheDir();
        }
    
        public function getLogDir()
        {
            if (in_array($this->environment, array('dev', 'test'))) {
                return '/dev/shm/appname/logs';
            }
    
            return parent::getLogDir();
        }
    }
    

    Source: http://www.whitewashing.de/2013/08/19/speedup_symfony2_on_vagrant_boxes.html

提交回复
热议问题